You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: modules/ROOT/pages/queries-aggregations/filtering.adoc
+49-36Lines changed: 49 additions & 36 deletions
Original file line number
Diff line number
Diff line change
@@ -3,12 +3,46 @@
3
3
:page-aliases: filtering.adoc
4
4
:description: This page describes filtering operators.
5
5
6
-
When querying for data, a number of operators are available for different types in the `where` argument of a query or mutation.
6
+
When querying for data, a number of operators are available for the types in the `where` argument of a query or mutation, allowing you to filter query results.
7
+
8
+
Operators can either be standalone operators (see xref:#_boolean_operators) or they are appended to field names (for example, xref:/queries-aggregations/filtering.adoc#_boolean_operators[`NOT`]).
9
+
10
+
All operators can be combined using the Boolean operators `AND`, `OR`, and `NOT`.
11
+
12
+
== Boolean operators
13
+
14
+
As standalone operators, Boolean operators accept an array argument with items of the same format as the `where` argument.
15
+
This way, they can be nested to form complex Boolean expressions.
16
+
17
+
For example, if you want to match all actors by the name of either "Keanu" or not belonging to the "Pantoliano" family, who played in "The Matrix" movie, here is how you query that:
18
+
19
+
[source, graphql, indent=0]
20
+
----
21
+
query {
22
+
actors(where: {
23
+
AND: [
24
+
{
25
+
OR: [
26
+
{ name_CONTAINS: "Keanu" },
27
+
{ NOT: { name_ENDS_WITH: "Pantoliano" } }
28
+
]
29
+
},
30
+
{
31
+
movies_SOME: { title: "The Matrix" }
32
+
}
33
+
]}
34
+
) {
35
+
name
36
+
movies {
37
+
title
38
+
}
39
+
}
40
+
}
41
+
----
7
42
8
43
== Equality operators
9
44
10
-
All types can be tested for either equality.
11
-
For non-equality, you *must* use the xref:/queries-aggregations/filtering.adoc#_logical_operators[`NOT`] logical operator.
45
+
All types can be tested for equality or non-equality.
12
46
For example:
13
47
14
48
.Filtering all users named John
@@ -21,6 +55,18 @@ query {
21
55
}
22
56
----
23
57
58
+
For non-equality, you must use the xref:/queries-aggregations/filtering.adoc#_boolean_operators[`NOT`] logical operator.
59
+
60
+
.Filtering all users which are not named John
61
+
[source, graphql, indent=0]
62
+
----
63
+
query {
64
+
users(where: { NOT: {name: "John" }})
65
+
id
66
+
name
67
+
}
68
+
----
69
+
24
70
[NOTE]
25
71
====
26
72
For the `Boolean` type, equality operators are the only ones available.
@@ -52,39 +98,6 @@ query {
52
98
Spatial types use numerical filtering differently and they also have additional options.
53
99
See xref:filtering.adoc#_filtering_spatial_types[Filtering spatial types] for more information.
54
100
55
-
== Logical operators
56
-
57
-
All operators can be combined using the logical operators `AND`, `OR`, and `NOT`.
58
-
They can also be standalone operators, which means that they can be used as such and not be appended to field names.
59
-
60
-
These operators accept an array argument with items of the same format as the `where` argument, which means they can also be nested to form complex combinations.
61
-
62
-
For example, if you want to match all actors by the name of either "Keanu" or not belonging to the "Pantoliano" family, that played in "The Matrix" movie, here is how you can query that:
0 commit comments