From 0786b2014bafc57f679432bd77440ae1bd7a8873 Mon Sep 17 00:00:00 2001 From: Sabina Talipova Date: Mon, 27 Nov 2023 08:27:28 +1300 Subject: [PATCH] DOC Add SortPlugin to the docs --- .../02_query_plugins.md | 44 ++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) diff --git a/en/02_Developer_Guides/19_GraphQL/02_working_with_dataobjects/02_query_plugins.md b/en/02_Developer_Guides/19_GraphQL/02_working_with_dataobjects/02_query_plugins.md index 2b1d96b02..1ac5039f7 100644 --- a/en/02_Developer_Guides/19_GraphQL/02_working_with_dataobjects/02_query_plugins.md +++ b/en/02_Developer_Guides/19_GraphQL/02_working_with_dataobjects/02_query_plugins.md @@ -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. @@ -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.