Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DOC Add SortPlugin to the docs #408

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ modelConfig:
filter: false
```

### The sort plugin
### The sort plugins

The sort plugin ([`QuerySort`](api:SilverStripe\GraphQL\Schema\DataObject\Plugin\QuerySort)) adds a
special `sort` argument to the `read` and `readOne` operations.
Expand Down Expand Up @@ -329,6 +329,48 @@ query {
}
```

In addition, you can use the field sorting plugin ([`SortPlugin`](api:SilverStripe\GraphQL\Schema\Plugin\SortPlugin)) to sort fields that represent `has_many` and `many_many` relationships. To do this, simply add the desired fields to the query, as well as the `sort` argument to these fields. It is also necessary to update the scheme by adding a `sorter` plugin to those fields that need to be sorted.

Example how to use SortPlugin.

```graphql
query {
readPages (
sort: { created: DESC }
) {
nodes {
title
created
hasManyFilesField (sort: { parentFolderID: DESC, title: ASC }) {
name
}
}
}
}
```
**app/_graphql/models.yml**
```yaml
MyProject\Models\Page:
operations:
read:
plugins:
sort:
before: paginateList
fields:
created: true
fields:
title: true
created: true
hasManyFilesField:
fields:
name: true
plugins:
sorter:
fields:
title: true
parentFolderID: true
```

#### Customising the sort fields

By default, all fields on the DataObject, including `has_one` relationships, are included.
Expand Down