Skip to content

Commit

Permalink
DOC Add SortPlugin to the docs
Browse files Browse the repository at this point in the history
  • Loading branch information
sabina-talipova committed Nov 27, 2023
1 parent e284cf1 commit 0786b20
Showing 1 changed file with 43 additions and 1 deletion.
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

0 comments on commit 0786b20

Please sign in to comment.