Skip to content

Commit

Permalink
feat(graphql,paging): Add NONE paging strategy
Browse files Browse the repository at this point in the history
  • Loading branch information
doug-martin committed Jun 18, 2020
1 parent 005ee15 commit 216d926
Show file tree
Hide file tree
Showing 57 changed files with 1,734 additions and 643 deletions.
8 changes: 8 additions & 0 deletions documentation/docs/faq.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,11 @@ Yes! You can specify a `pagingStrategy` option to customize how paging is handle
For more information and examples check out the following docs
* [Resolver Paging Strategy](./graphql/resolvers.mdx#paging-strategy)
* [Relations](./graphql/relations.mdx#many-relation)

## Can I use turn off paging?

Yes! You can specify a `pagingStrategy` option to customize how paging is handled at the resolver or relation level.

For more information and examples check out the following docs
* [Resolver Paging Strategy](./graphql/resolvers.mdx#paging-strategy)
* [Relations](./graphql/relations.mdx#many-relation)
298 changes: 297 additions & 1 deletion documentation/docs/graphql/queries.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -748,7 +748,7 @@ In this example we sort by completed and title.

An alternative to cursor based querying is to use the `OFFSET` `pagingStrategy` described is the [resolvers documentation](./resolvers.mdx#options)

When using the strategy queries that return multiple records will return an array instead of a connection.
When using the strategy queries that return multiple records will return an `ArrayConnection` instead of a `CursorConnection`.

<Tabs
defaultValue="graphql"
Expand Down Expand Up @@ -1148,3 +1148,299 @@ In this example we sort by completed and title.
```
</TabItem>
</Tabs>

## No Paging Based Querying

When using the `NONE` paging strategy the `paging` argument is removed and all methods will return an `ArrayConnection`.

When using the strategy queries that return multiple records will return an array instead of a connection.

<Tabs
defaultValue="graphql"
values={[
{ label: 'GraphQL', value: 'graphql', },
{ label: 'Response', value: 'response', },
]
}>
<TabItem value="graphql">

```graphql
{
todoItems {
id
title
completed
created
updated
}
}
```


</TabItem>
<TabItem value="response">


```json
{
"data": {
"todoItems": [
{
"id": "1",
"title": "Create Nest App",
"completed": true,
"created": "2020-06-12T08:15:18.876Z",
"updated": "2020-06-12T08:15:18.876Z"
},
{
"id": "2",
"title": "Create Entity",
"completed": false,
"created": "2020-06-12T08:15:18.876Z",
"updated": "2020-06-12T08:15:18.876Z"
},
{
"id": "3",
"title": "Create Entity Service",
"completed": false,
"created": "2020-06-12T08:15:18.876Z",
"updated": "2020-06-12T08:15:18.876Z"
},
{
"id": "4",
"title": "Add Todo Item Resolver",
"completed": false,
"created": "2020-06-12T08:15:18.876Z",
"updated": "2020-06-12T08:15:18.876Z"
},
{
"id": "5",
"title": "How to create item With Sub Tasks",
"completed": false,
"created": "2020-06-12T08:15:18.876Z",
"updated": "2020-06-12T08:15:18.876Z"
}
]
}
}
```

</TabItem>
</Tabs>

---

### Filtering

Filtering in `query-graphql` has has an object based syntax

For a full reference of filter operations [see filter reference](../concepts/queries#filter-reference)

The following example filters for all todoItems that are marked completed.

<Tabs
defaultValue="graphql"
values={[
{ label: 'GraphQL', value: 'graphql', },
{ label: 'Response', value: 'response', },
]
}>
<TabItem value="graphql">

```graphql
{
todoItems(filter: {completed: {is: true}}) {
id
title
completed
created
updated
}
}
```

</TabItem>
<TabItem value="response">

```json
{
"data": {
"todoItems": [
{
"id": "1",
"title": "Create Nest App",
"completed": true,
"created": "2020-06-12T08:44:43.555Z",
"updated": "2020-06-12T08:44:43.555Z"
}
]
}
}
```

</TabItem>
</Tabs>

---

### Sorting

You can sort by one or more fields by using the `sorting` parameter.

The `sorting` parameter is an array where each item has the following options.

* `field!` - The name of the field to sort by.
* `direction!` - The direction to sort either `ASC` or `DESC`.
* `nulls?` - Optional field to set nulls sort order `NULLS_FIRST` or `NULLS_last`

In this example we sort by title descending.

<Tabs
defaultValue="graphql"
values={[
{ label: 'GraphQL', value: 'graphql', },
{ label: 'Response', value: 'response', },
]
}>
<TabItem value="graphql">

```graphql
{
todoItems(sorting: [{ field: title, direction: DESC }]) {
id
title
completed
created
updated
}
}


```

</TabItem>
<TabItem value="response">

```json
{
"data": {
"todoItems": [
{
"id": "5",
"title": "How to create item With Sub Tasks",
"completed": false,
"created": "2020-06-12T08:44:43.555Z",
"updated": "2020-06-12T08:44:43.555Z"
},
{
"id": "1",
"title": "Create Nest App",
"completed": true,
"created": "2020-06-12T08:44:43.555Z",
"updated": "2020-06-12T08:44:43.555Z"
},
{
"id": "3",
"title": "Create Entity Service",
"completed": false,
"created": "2020-06-12T08:44:43.555Z",
"updated": "2020-06-12T08:44:43.555Z"
},
{
"id": "2",
"title": "Create Entity",
"completed": false,
"created": "2020-06-12T08:44:43.555Z",
"updated": "2020-06-12T08:44:43.555Z"
},
{
"id": "4",
"title": "Add Todo Item Resolver",
"completed": false,
"created": "2020-06-12T08:44:43.555Z",
"updated": "2020-06-12T08:44:43.555Z"
}
]
}
}
```
</TabItem>
</Tabs>

In this example we sort by completed and title.

<Tabs
defaultValue="graphql"
values={[
{ label: 'GraphQL', value: 'graphql', },
{ label: 'Response', value: 'response', },
]
}>
<TabItem value="graphql">

```graphql
{
todoItems(
sorting: [
{ field: completed, direction: DESC }
{ field: title, direction: DESC }
]
) {
id
title
completed
created
updated
}
}

```

</TabItem>
<TabItem value="response">

```json
{
"data": {
"todoItems": [
{
"id": "1",
"title": "Create Nest App",
"completed": true,
"created": "2020-06-12T08:44:43.555Z",
"updated": "2020-06-12T08:44:43.555Z"
},
{
"id": "5",
"title": "How to create item With Sub Tasks",
"completed": false,
"created": "2020-06-12T08:44:43.555Z",
"updated": "2020-06-12T08:44:43.555Z"
},
{
"id": "3",
"title": "Create Entity Service",
"completed": false,
"created": "2020-06-12T08:44:43.555Z",
"updated": "2020-06-12T08:44:43.555Z"
},
{
"id": "2",
"title": "Create Entity",
"completed": false,
"created": "2020-06-12T08:44:43.555Z",
"updated": "2020-06-12T08:44:43.555Z"
},
{
"id": "4",
"title": "Add Todo Item Resolver",
"completed": false,
"created": "2020-06-12T08:44:43.555Z",
"updated": "2020-06-12T08:44:43.555Z"
}
]
}
}
```
</TabItem>
</Tabs>
12 changes: 11 additions & 1 deletion documentation/docs/graphql/relations.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ When using the `nestjs-query` you can specify relations that should be exposed f

* `@Relation` - A relation that is:
* a single value (one-to-one, many-to-one)
* an array of values that should use `OFFSET` based paging.
* an array of values that should use `OFFSET` or `NONE` paging.
* `@Connection` - A connection that represents a collection that should use `cursor` based pagination. (e.g, many-to-many, one-to-many)

:::note
Expand Down Expand Up @@ -252,6 +252,14 @@ When specifying a many relation a couple of endpoints will automatically be gene
* The `subTasks` will be returned as an array of results.
* `addSubTasksToTodoItem` - A `mutation` to add `SubTasks` to a `TodoItem`.

:::note
You can disable paging by setting the `pagingStrategy` option to `PagingStrategies.NONE`.
```ts
@Relation('subTasks', () => [SubTaskDTO], { pagingStrategy: PagingStrategies.NONE, disableRemove: true })
```
:::


:::note
In this example we `disableRemove` because `SubTasks` cannot exist without a `TodoItem`.
:::
Expand Down Expand Up @@ -678,6 +686,8 @@ export class SubTaskResolver extends CRUDResolver(SubTaskDTO, {

You can also specify the `pagingStrategy` option to change the default paging behavior for a single relation.

The `pagingStrategy` can be set to `OFFSET` or `NONE`.

In this example we'll disable connections and cursor based paging in favor of an `OFFSET` based strategy that returns an array of values.

```ts title="todo-item/todo-item.resolver.ts" {9-11}
Expand Down
Loading

0 comments on commit 216d926

Please sign in to comment.