Skip to content

Commit d6c0685

Browse files
committed
navigation structure, text updates
1 parent 5b1c628 commit d6c0685

File tree

1 file changed

+95
-86
lines changed

1 file changed

+95
-86
lines changed

modules/ROOT/pages/queries-aggregations/filtering.adoc

Lines changed: 95 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,18 @@
55

66
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.
77

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[]).
99

1010
All operators can be combined using the Boolean operators `AND`, `OR`, and `NOT`.
1111

12-
== Boolean operators
12+
== Operators
13+
14+
=== Boolean operators
1315

1416
As standalone operators, Boolean operators accept an array argument with items of the same format as the `where` argument.
1517
This way, they can be nested to form complex Boolean expressions.
1618

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:
1820

1921
[source, graphql, indent=0]
2022
----
@@ -40,7 +42,9 @@ query {
4042
}
4143
----
4244

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
4448

4549
All types can be tested for equality or non-equality.
4650
For example:
@@ -72,7 +76,7 @@ query {
7276
For the `Boolean` type, equality operators are the only ones available.
7377
====
7478

75-
== Numerical operators
79+
=== Numerical operators
7680

7781
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:
7882

@@ -98,10 +102,72 @@ query {
98102
Spatial types use numerical filtering differently and they also have additional options.
99103
See xref:filtering.adoc#_filtering_spatial_types[Filtering spatial types] for more information.
100104

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`:
127+
128+
[source, graphql, indent=0]
129+
----
130+
query CloseByUsers($longitude: Float!, $latitude: Float!) {
131+
users(where: { location_LTE: { point: { longitude: $longitude, latitude: $latitude }, distance: 5000 } }) {
132+
name
133+
location {
134+
longitude
135+
latitude
136+
}
137+
}
138+
}
139+
----
140+
141+
Similarly, for a `CartesianPoint` type, all filters take the following type as an argument:
142+
143+
[source, graphql, indent=0]
144+
----
145+
input CartesianPointDistance {
146+
point: CartesianPoint!
147+
distance: Float!
148+
}
149+
----
150+
151+
The same query for a `CartesianPoint`:
152+
153+
[source, graphql, indent=0]
154+
----
155+
query CloseByUsers($x: Float!, $y: Float!) {
156+
users(where: { location_LTE: { point: { x: $x, y: $y }, distance: 5000 } }) {
157+
name
158+
location {
159+
x
160+
y
161+
}
162+
}
163+
}
164+
----
165+
166+
== Type comparison
101167

102-
== String comparison
168+
=== String comparison
103169

104-
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:
105171

106172
* `_STARTS_WITH`
107173
* `_ENDS_WITH`
@@ -154,16 +220,17 @@ const features = {
154220
const neoSchema = new Neo4jGraphQL({ features, typeDefs, driver });
155221
----
156222

157-
== RegEx matching
223+
=== RegEx matching
158224

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.
160226
It accepts RegEx strings as an argument and returns any matches.
161227

162-
163-
Note that RegEx matching filters are **disabled by default**.
228+
Note that RegEx matching filters are disabled by default.
164229
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.
165230

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`:
167234

168235
[source, javascript, indent=0]
169236
----
@@ -213,7 +280,7 @@ const features = {
213280
const neoSchema = new Neo4jGraphQL({ features, typeDefs, driver });
214281
----
215282

216-
== Array comparison
283+
=== Array comparison
217284

218285
The following operator is available on non-array fields, and accepts an array argument:
219286

@@ -225,84 +292,23 @@ Conversely, the following operator is available on array fields, and accepts a s
225292

226293
These operators are available for all types apart from `Boolean`.
227294

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`:
250-
251-
[source, graphql, indent=0]
252-
----
253-
query CloseByUsers($longitude: Float!, $latitude: Float!) {
254-
users(where: { location_LTE: { point: { longitude: $longitude, latitude: $latitude }, distance: 5000 } }) {
255-
name
256-
location {
257-
longitude
258-
latitude
259-
}
260-
}
261-
}
262-
----
263-
264-
Similarly, for a `CartesianPoint` type, all filters take the following type as an argument:
265-
266-
[source, graphql, indent=0]
267-
----
268-
input CartesianPointDistance {
269-
point: CartesianPoint!
270-
distance: Float!
271-
}
272-
----
273-
274-
The same query for a `CartesianPoint`:
275-
276-
[source, graphql, indent=0]
277-
----
278-
query CloseByUsers($x: Float!, $y: Float!) {
279-
users(where: { location_LTE: { point: { x: $x, y: $y }, distance: 5000 } }) {
280-
name
281-
location {
282-
x
283-
y
284-
}
285-
}
286-
}
287-
----
288-
289-
== Querying an interface
295+
== Interface filtering
290296

291297
You can use the `typename_IN` filter to filter interfaces.
292298
Refer to xref:types/interfaces.adoc#type-definitions-interfaced-types-querying[Type definitions -> Type -> Interface] for more details and an example.
293299

294300
== Relationship filtering
295301

296-
Relationship filtering depends on the type of relationship that you have:
302+
Relationship filtering depends on the type of relationship:
297303

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:
300306
** `field_ALL` - https://neo4j.com/docs/cypher-manual/current/functions/predicate/#functions-all[all]
301307
** `field_NONE` - https://neo4j.com/docs/cypher-manual/current/functions/predicate/#functions-none[none]
302308
** `field_SOME` - https://neo4j.com/docs/cypher-manual/current/functions/predicate/#functions-any[any]
303309
** `field_SINGLE` - https://neo4j.com/docs/cypher-manual/current/functions/predicate/#functions-single[single]
304310

305-
As an example, take these type definitions:
311+
For example, take these type definitions:
306312

307313
[source, graphql, indent=0]
308314
----
@@ -319,10 +325,12 @@ type Post {
319325
likes: [User!]! @relationship(type: "LIKES", direction: IN)
320326
}
321327
----
328+
322329
=== `n..1` relationships
323330

324-
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+
326334
For example:
327335

328336
.Find all posts by a desired author
@@ -347,8 +355,9 @@ query {
347355

348356
=== `n..m` relationships
349357

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:
352361

353362
.Find all users where all of their posts contain search term: `"neo4j"`
354363
[source, graphql, indent=0]
@@ -392,8 +401,8 @@ query {
392401

393402
== Aggregation filtering
394403

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 offers an aggregation key inside the `where` argument of each relationship.
405+
You can use it both on the `node` and `edge` of a relationship.
397406

398407
Here are some examples on how to apply this kind of filtering:
399408

@@ -477,7 +486,7 @@ query {
477486
}
478487
----
479488

480-
=== Operators
489+
=== With operators
481490

482491
Aggregation filtering can also be done with operators.
483492
They provide autogenerated filters available for each type on the `node` and `edge` of the specified relationship.

0 commit comments

Comments
 (0)