Skip to content

Commit 349cdec

Browse files
authored
Explain the new filter syntax (#1185)
1 parent 87bf9cb commit 349cdec

File tree

1 file changed

+41
-2
lines changed

1 file changed

+41
-2
lines changed

core/graphql.md

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -588,7 +588,7 @@ The cache is named `api_platform.graphql.cache.subscription` and the subscriptio
588588

589589
It's recommended to use an adapter like Redis for this cache.
590590

591-
## Workflow of the Resolvers
591+
## Workflow of the Resolvers
592592

593593
API Platform resolves the queries and mutations by using its own **resolvers**.
594594

@@ -757,6 +757,45 @@ class Offer
757757
}
758758
```
759759

760+
### Syntax for Filters with a List of Key / Value Arguments
761+
762+
Some filters like the [exists filter](filters.md#exists-filter) or the [order filter](filters.md#order-filter-sorting) take a list of key / value as arguments.
763+
764+
The first syntax coming to mind to use them is to write:
765+
766+
```graphql
767+
{
768+
offers(order: {id: "ASC", name: "DESC"}) {
769+
edges {
770+
node {
771+
id
772+
name
773+
}
774+
}
775+
}
776+
}
777+
```
778+
779+
However this syntax has a problematic issue: it doesn't keep the order of the arguments.
780+
These filters usually need a proper order to give results as expected.
781+
782+
That's why this syntax needs to be used instead:
783+
784+
```graphql
785+
{
786+
offers(order: [{id: "ASC"}, {name: "DESC"}]) {
787+
edges {
788+
node {
789+
id
790+
name
791+
}
792+
}
793+
}
794+
}
795+
```
796+
797+
Since a list is used for the arguments, the order is preserved.
798+
760799
### Filtering on Nested Properties
761800

762801
Unlike for REST, all built-in filters support nested properties using the underscore (`_`) syntax instead of the dot (`.`) syntax, e.g.:
@@ -806,7 +845,7 @@ Or order your results like:
806845

807846
```graphql
808847
{
809-
offers(order: {product_releaseDate: "DESC"}) {
848+
offers(order: [{product_releaseDate: "DESC"}]) {
810849
edges {
811850
node {
812851
id

0 commit comments

Comments
 (0)