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
+95-86Lines changed: 95 additions & 86 deletions
Original file line number
Diff line number
Diff line change
@@ -5,16 +5,18 @@
5
5
6
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
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`]).
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#_string_comparison[]).
9
9
10
10
All operators can be combined using the Boolean operators `AND`, `OR`, and `NOT`.
11
11
12
-
== Boolean operators
12
+
== Operators
13
+
14
+
=== Boolean operators
13
15
14
16
As standalone operators, Boolean operators accept an array argument with items of the same format as the `where` argument.
15
17
This way, they can be nested to form complex Boolean expressions.
16
18
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:
19
+
For example, if you want to match all actors either by the name of "Keanu" or not belonging to the "Pantoliano" family, who played in "The Matrix" movie, here is how you query that:
18
20
19
21
[source, graphql, indent=0]
20
22
----
@@ -40,7 +42,9 @@ query {
40
42
}
41
43
----
42
44
43
-
== Equality operators
45
+
`name_CONTAINS` and `name_ENDS_WITH` are xref:/queries-aggregations/filtering.adoc#_string_comparison[String comparisons] while `movies_SOME` is a xref:/queries-aggregations/filtering.adoc#_relationship_filtering[relationship filter].
46
+
47
+
=== Equality operators
44
48
45
49
All types can be tested for equality or non-equality.
46
50
For example:
@@ -72,7 +76,7 @@ query {
72
76
For the `Boolean` type, equality operators are the only ones available.
73
77
====
74
78
75
-
== Numerical operators
79
+
=== Numerical operators
76
80
77
81
These are the operators available for numeric (`Int`, `Float`, xref::/types/scalar.adoc[`BigInt`]), xref::/types/temporal.adoc[temporal] and xref::/types/spatial.adoc[spatial] types:
78
82
@@ -98,10 +102,72 @@ query {
98
102
Spatial types use numerical filtering differently and they also have additional options.
99
103
See xref:filtering.adoc#_filtering_spatial_types[Filtering spatial types] for more information.
100
104
105
+
==== Spatial type filtering
106
+
107
+
Both the `Point` and the `CartesianPoint` types use xref::queries-aggregations/filtering.adoc#_numerical_operators[numerical operators] and have an additional `_DISTANCE` filter.
108
+
Here is a list of what each filter does for the two types:
109
+
110
+
* `_LT`: checks if a point is less than the distance in the `distance` field away (in meters) from the point specified by the `point` field.
111
+
* `_LTE`: checks if a point is less than or equal to the distance in the `distance` field away (in meters) from the point specified by the `point` field.
112
+
* `_DISTANCE`: checks if a point is the exact distance in the `distance` field away (in meters) from the point specified by the `point` field.
113
+
* `_GT`: checks if a point is greater than the distance in the `distance` field away (in meters) from the point specified by the `point` field.
114
+
* `_GTE`: checks if a point is greater than or equal to the distance in the `distance` field away (in meters) from the point specified by the `point` field.
115
+
116
+
For a `Point` type, all filters take the following type as an argument:
117
+
118
+
[source, graphql, indent=0]
119
+
----
120
+
input PointDistance {
121
+
point: Point!
122
+
distance: Float!
123
+
}
124
+
----
125
+
126
+
In practice, you can construct queries like the following, which finds all users within a 5km (5000m) radius of a `Point`:
The following case-sensitive comparison operators are only available for use on `String` and `ID` types:
170
+
The following case-sensitive comparison operators are available for `String` and `ID` types:
105
171
106
172
* `_STARTS_WITH`
107
173
* `_ENDS_WITH`
@@ -154,16 +220,17 @@ const features = {
154
220
const neoSchema = new Neo4jGraphQL({ features, typeDefs, driver });
155
221
----
156
222
157
-
== RegEx matching
223
+
=== RegEx matching
158
224
159
-
The filter `_MATCHES` is also available for comparison of `String` and `ID` types.
225
+
The filter `_MATCHES` is available for comparison of `String` and `ID` types.
160
226
It accepts RegEx strings as an argument and returns any matches.
161
227
162
-
163
-
Note that RegEx matching filters are **disabled by default**.
228
+
Note that RegEx matching filters are disabled by default.
164
229
This is because, on an unprotected API, they could potentially be used to execute a https://owasp.org/www-community/attacks/Regular_expression_Denial_of_Service_-_ReDoS[ReDoS attack^] against the backing Neo4j database.
165
230
166
-
If you want to enable them, set the features configuration object for each:
231
+
If you want to enable RegEx matching, update the `features` configuration object.
232
+
233
+
For `String`:
167
234
168
235
[source, javascript, indent=0]
169
236
----
@@ -213,7 +280,7 @@ const features = {
213
280
const neoSchema = new Neo4jGraphQL({ features, typeDefs, driver });
214
281
----
215
282
216
-
== Array comparison
283
+
=== Array comparison
217
284
218
285
The following operator is available on non-array fields, and accepts an array argument:
219
286
@@ -225,84 +292,23 @@ Conversely, the following operator is available on array fields, and accepts a s
225
292
226
293
These operators are available for all types apart from `Boolean`.
227
294
228
-
== Filtering spatial types
229
-
230
-
Both the `Point` and the `CartesianPoint` types use xref::queries-aggregations/filtering.adoc#_numerical_operators[numerical operators] and have an additional `_DISTANCE` filter.
231
-
Here is a list of what each filter does for the two types:
232
-
233
-
* `_LT`: checks if a point is less than the distance in the `distance` field away (in meters) from the point specified by the `point` field.
234
-
* `_LTE`: checks if a point is less than or equal to the distance in the `distance` field away (in meters) from the point specified by the `point` field.
235
-
* `_DISTANCE`: checks if a point is the exact distance in the `distance` field away (in meters) from the point specified by the `point` field.
236
-
* `_GT`: checks if a point is greater than the distance in the `distance` field away (in meters) from the point specified by the `point` field.
237
-
* `_GTE`: checks if a point is greater than or equal to the distance in the `distance` field away (in meters) from the point specified by the `point` field.
238
-
239
-
For a `Point` type, all filters take the following type as an argument:
240
-
241
-
[source, graphql, indent=0]
242
-
----
243
-
input PointDistance {
244
-
point: Point!
245
-
distance: Float!
246
-
}
247
-
----
248
-
249
-
In practice, you can construct queries like the following, which finds all users within a 5km (5000m) radius of a `Point`:
You can use the `typename_IN` filter to filter interfaces.
292
298
Refer to xref:types/interfaces.adoc#type-definitions-interfaced-types-querying[Type definitions -> Type -> Interface] for more details and an example.
293
299
294
300
== Relationship filtering
295
301
296
-
Relationship filtering depends on the type of relationship that you have:
302
+
Relationship filtering depends on the type of relationship:
297
303
298
-
* `n..1`: filtering done on equality or inequality of the related nodes by specifying a filter on `field`.
299
-
* `n..m`: filtering is done on the list of related nodes and is based on the https://neo4j.com/docs/cypher-manual/current/functions/predicate/[list predicates] available in Cypher:
304
+
* `n..1`: the filtering is done on equality or inequality of the related nodes by specifying a filter on `field`.
305
+
* `n..m`: the filtering is done on the list of related nodes and is based on the https://neo4j.com/docs/cypher-manual/current/functions/predicate/[list predicates] available in Cypher:
An `author` represents an `n..1` relationship on `Post`, where a given `Post` is authored by one, and only one, `author`.
325
-
The available filters here will be `author`.
331
+
In the type definitions example, an `author` represents an `n..1` relationship on `Post`, where a given `Post` is authored by one, and only one, `author`.
332
+
The available filter is `author`.
333
+
326
334
For example:
327
335
328
336
.Find all posts by a desired author
@@ -347,8 +355,9 @@ query {
347
355
348
356
=== `n..m` relationships
349
357
350
-
In the previous example, `posts` represents a `n..m` relationship on `User`, where a given `User` can have any number of `posts`.
351
-
Here are some query examples:
358
+
In the type definitions example, `posts` represents an `n..m` relationship on `User`, where a given `User` can have any number of `posts`.
359
+
360
+
For example:
352
361
353
362
.Find all users where all of their posts contain search term: `"neo4j"`
354
363
[source, graphql, indent=0]
@@ -392,8 +401,8 @@ query {
392
401
393
402
== Aggregation filtering
394
403
395
-
This library offers, for each relationship, an aggregation key inside the `where` argument.
396
-
It can be used both on the `node` and `edge` of a relationship.
404
+
The Neo4j GraphQL library offersan aggregation key inside the `where` argument of each relationship.
405
+
You can use it both on the `node` and `edge` of a relationship.
397
406
398
407
Here are some examples on how to apply this kind of filtering:
399
408
@@ -477,7 +486,7 @@ query {
477
486
}
478
487
----
479
488
480
-
=== Operators
489
+
=== With operators
481
490
482
491
Aggregation filtering can also be done with operators.
483
492
They provide autogenerated filters available for each type on the `node` and `edge` of the specified relationship.
0 commit comments