Skip to content

Commit aa73412

Browse files
committed
moved the filtering page to make it more prominent, tidied up the queries-aggregations section a bit
1 parent a2ffd8b commit aa73412

File tree

14 files changed

+225
-211
lines changed

14 files changed

+225
-211
lines changed

modules/ROOT/content-nav.adoc

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
** xref:types/interfaces.adoc[Interfaces]
2121
** xref:types/unions.adoc[Union]
2222
** xref:types/relationships.adoc[]
23+
* xref:filtering.adoc[]
2324
* xref:neo4jgraphql-class.adoc[]
2425
* xref:directives/index.adoc[]
2526
** xref:directives/database-mapping.adoc[]
@@ -35,11 +36,8 @@
3536
* xref:queries-aggregations/index.adoc[Queries and aggregations]
3637
** xref:queries-aggregations/queries.adoc[]
3738
** xref:queries-aggregations/aggregations.adoc[]
38-
** xref:queries-aggregations/filtering.adoc[]
3939
** xref:queries-aggregations/sorting.adoc[]
40-
** xref:queries-aggregations/pagination/index.adoc[]
41-
*** xref:queries-aggregations/pagination/offset-based.adoc[]
42-
*** xref:queries-aggregations/pagination/cursor-based.adoc[]
40+
** xref:queries-aggregations/pagination.adoc[]
4341
4442
* xref:mutations/index.adoc[]
4543
** xref:mutations/create.adoc[]

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

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
[[filtering]]
22
= Filtering
3-
:page-aliases: filtering.adoc
3+
:page-aliases: queries-aggregations/filtering.adoc
44
:description: This page describes filtering operators.
55

6+
You can apply filters when you query or aggregate data as well as use filtering rules for xref::/security/authorization.adoc#_filtering_rules[authorization].
7+
68
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 or specify the set of objects a mutation applies to.
79

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[]).
10+
Operators can either be standalone operators (see xref:#_boolean_operators[]) or they are appended to field names (for example, xref:#_string_comparison[]).
911

1012
All operators can be combined using the Boolean operators `AND`, `OR`, and `NOT`.
1113

@@ -42,7 +44,7 @@ query {
4244
}
4345
----
4446

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].
47+
`name_CONTAINS` and `name_ENDS_WITH` are xref:#_string_comparison[String comparisons] while `movies_SOME` is a xref:#_relationship_filtering[relationship filter].
4648

4749
=== Equality operators
4850

@@ -60,7 +62,7 @@ query {
6062
}
6163
----
6264

63-
For non-equality, you must use the xref:/queries-aggregations/filtering.adoc#_boolean_operators[`NOT`] logical operator.
65+
For non-equality, you must use the xref:#_boolean_operators[`NOT`] logical operator.
6466

6567
.Filtering all users which are not named John
6668
[source, graphql, indent=0]
@@ -101,11 +103,11 @@ query {
101103
----
102104

103105
Spatial types use numerical filtering differently and they also have additional options.
104-
See xref:filtering.adoc#_filtering_spatial_types[Filtering spatial types] for more information.
106+
See xref:filtering.adoc#_spatial_type_filtering[] for more information.
105107

106108
==== Spatial type filtering
107109

108-
Both the `Point` and the `CartesianPoint` types use xref::queries-aggregations/filtering.adoc#_numerical_operators[numerical operators] and have an additional `_DISTANCE` filter.
110+
Both the `Point` and the `CartesianPoint` types use xref:#_numerical_operators[numerical operators] and have an additional `_DISTANCE` filter.
109111
Here is a list of what each filter does for the two types:
110112

111113
* `_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.

modules/ROOT/pages/index.adoc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ For every query and mutation that is executed against this generated schema, the
2727
- xref::/types/index.adoc[Types], including temporal and spatial.
2828
- Support for both node and relationship properties.
2929
- Extensibility through the xref::/directives/custom-logic.adoc#_cypher[`@cypher` directive] and/or xref::/directives/custom-logic.adoc#_customresolver[Custom Resolvers].
30-
- Extensive xref::queries-aggregations/filtering.adoc[Filtering] and xref::queries-aggregations/sorting.adoc[Sorting] options.
30+
- Extensive xref::filtering.adoc[Filtering] and xref::queries-aggregations/sorting.adoc[Sorting] options.
3131
- Options for xref::/directives/database-mapping.adoc[Database mapping] and value xref::/directives/autogeneration.adoc[Autogeneration].
32-
- xref::/queries-aggregations/pagination/index.adoc[Pagination] options.
32+
- xref::/queries-aggregations/pagination.adoc[Pagination] options.
3333
- xref::/security/index.adoc[Security options] and additional xref::schema-configuration/index.adoc[Schema Configuration].
3434
- An xref::ogm/index.adoc[OGM] (Object Graph Mapper) for programmatic interaction with your GraphQL API.
3535
- A xref::getting-started/toolbox.adoc[Toolbox] (UI) to experiment with your Neo4j GraphQL API on Neo4j Desktop.

modules/ROOT/pages/neo4jgraphql-class.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ export type Neo4jFeaturesSettings = {
5353

5454
Use `Neo4jFiltersSettings` to enable numeric String comparisons and regular expression filters for Strings and IDs.
5555
They are disabled by default.
56-
See xref:queries-aggregations/filtering.adoc#_string_comparison[String comparison] and xref:queries-aggregations/filtering.adoc#_regex_matching[RegEx matching].
56+
See xref:filtering.adoc#_string_comparison[String comparison] and xref:filtering.adoc#_regex_matching[RegEx matching].
5757

5858

5959
=== `populatedBy` settings

modules/ROOT/pages/ogm/reference.adoc

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ This method can be used to aggregate nodes, and maps to the underlying schema xr
200200

201201
|`where`
202202
|`GraphQLWhereArg`
203-
|A JavaScript object representation of the GraphQL `where` input type used for xref::queries-aggregations/filtering.adoc[Filtering].
203+
|A JavaScript object representation of the GraphQL `where` input type used for xref::filtering.adoc[Filtering].
204204
|===
205205

206206
==== Example
@@ -310,7 +310,7 @@ It returns a `Promise` which resolves to a `DeleteInfo` object:
310310

311311
|`where`
312312
|`GraphQLWhereArg`
313-
|A JavaScript object representation of the GraphQL `where` input type used for xref::queries-aggregations/filtering.adoc[Filtering].
313+
|A JavaScript object representation of the GraphQL `where` input type used for xref::filtering.adoc[Filtering].
314314

315315
|`delete`
316316
|`string` or `DocumentNode` or `SelectionSetNode`
@@ -350,11 +350,11 @@ It returns a `Promise` which resolves to an array of objects matching the type o
350350

351351
|`where`
352352
|`GraphQLWhereArg`
353-
|A JavaScript object representation of the GraphQL `where` input type used for xref::queries-aggregations/filtering.adoc[Filtering].
353+
|A JavaScript object representation of the GraphQL `where` input type used for xref::filtering.adoc[Filtering].
354354

355355
|`options`
356356
|`GraphQLOptionsArg`
357-
|A JavaScript object representation of the GraphQL `options` input type used for xref::queries-aggregations/sorting.adoc[Sorting] and xref::/queries-aggregations/pagination/index.adoc[Pagination].
357+
|A JavaScript object representation of the GraphQL `options` input type used for xref::queries-aggregations/sorting.adoc[Sorting] and xref::/queries-aggregations/pagination.adoc[Pagination].
358358

359359
|`selectionSet`
360360
|`string` or `DocumentNode` or `SelectionSetNode`
@@ -408,7 +408,7 @@ It returns a `Promise` that resolves to the equivalent of the mutation response
408408

409409
|`where`
410410
|`GraphQLWhereArg`
411-
|A JavaScript object representation of the GraphQL `where` input type used for xref::queries-aggregations/filtering.adoc[Filtering].
411+
|A JavaScript object representation of the GraphQL `where` input type used for xref::filtering.adoc[Filtering].
412412

413413
|`update`
414414
|`any`
@@ -428,7 +428,7 @@ It returns a `Promise` that resolves to the equivalent of the mutation response
428428

429429
|`options`
430430
|`GraphQLOptionsArg`
431-
|A JavaScript object representation of the GraphQL `options` input type used for xref::queries-aggregations/sorting.adoc[Sorting] and xref::/queries-aggregations/pagination/index.adoc[Pagination].
431+
|A JavaScript object representation of the GraphQL `options` input type used for xref::queries-aggregations/sorting.adoc[Sorting] and xref::/queries-aggregations/pagination.adoc[Pagination].
432432

433433
|`selectionSet`
434434
|`string` or `DocumentNode` or `SelectionSetNode`

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ query {
9797

9898
[NOTE]
9999
====
100-
The argument `where` can also be used in aggregation queries for xref::queries-aggregations/filtering.adoc[filtering] data.
100+
The argument `where` can also be used in aggregation queries for xref::filtering.adoc[filtering] data.
101101
====
102102

103103
== Aggregate related nodes

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ This section addresses the following topics:
1010

1111
* xref:queries-aggregations/queries.adoc[Queries] - Read or fetch values.
1212
* xref:queries-aggregations/aggregations.adoc[Aggregations] - Combine lists of types from different sources into a single list.
13-
* xref:queries-aggregations/filtering.adoc[Filtering] - Filter query results to find objects.
1413
* xref:queries-aggregations/sorting.adoc[Sorting] - Sort query results by individual fields.
15-
* xref:queries-aggregations/pagination/index.adoc[Pagination] - Navigate result pages.
14+
* xref:queries-aggregations/pagination.adoc[Pagination] - Navigate result pages.
15+
16+
Also, refer to xref:filtering.adoc[Filtering] for details on how to filter query results to find objects.
Lines changed: 196 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,196 @@
1+
[[pagination]]
2+
= Pagination
3+
:page-aliases: pagination/index.adoc, pagination/offset-based.adoc, pagination/cursor-based.adoc, queries-aggregation/pagination/index.adoc, queries-aggregation/pagination/offset-based.adoc, queries-aggregation/pagination/cursor-based.adoc
4+
5+
6+
The Neo4j GraphQL Library offers two mechanisms for pagination:
7+
8+
* Offset-based pagination - Pagination based on offsets, often associated with navigation via pages.
9+
* Cursor-based pagination - Pagination based on cursors, often associated with infinitely-scrolling applications.
10+
11+
12+
[[pagination-offset-based]]
13+
== Offset-based pagination
14+
15+
Offset-based pagination, often associated with navigation via pages, can be achieved through the use of the `offset` and `limit` options available when querying for data.
16+
17+
Using the following type definition:
18+
19+
[source, graphql, indent=0]
20+
----
21+
type User {
22+
name: String!
23+
}
24+
----
25+
26+
Fetch the first page of 10 by executing:
27+
28+
[source, graphql, indent=0]
29+
----
30+
query {
31+
users(options: {
32+
limit: 10
33+
}) {
34+
name
35+
}
36+
}
37+
----
38+
39+
And then on subsequent calls, introduce the `offset` argument and increment it by 10 on each call.
40+
41+
Fetch the second page with:
42+
43+
[source, graphql, indent=0]
44+
----
45+
query {
46+
users(options: {
47+
offset: 10
48+
limit: 10
49+
}) {
50+
name
51+
}
52+
}
53+
----
54+
55+
Fetch the third page with:
56+
57+
[source, graphql, indent=0]
58+
----
59+
query {
60+
users(options: {
61+
offset: 20
62+
limit: 10
63+
}) {
64+
name
65+
}
66+
}
67+
----
68+
69+
And so on.
70+
71+
72+
=== Total number of pages
73+
74+
You can fetch the total number of records for a certain type using its count query, and then divide that number by your entries per page in order to calculate the total number of pages.
75+
This determines what the last page is, and whether there is a next page.
76+
77+
See xref::queries-aggregations/aggregations.adoc#_aggregate_related_nodes[count aggregation queries] for details on how to execute these queries.
78+
79+
80+
=== Paginating relationship fields
81+
82+
Say that in addition to the `User` type above, there is also a `Post` type which a `User` has many of.
83+
You can also fetch a `User` and then paginate through their posts:
84+
85+
[source, graphql, indent=0]
86+
----
87+
query {
88+
users(where: {
89+
name: "Billy"
90+
}) {
91+
name
92+
posts(options: {
93+
offset: 20
94+
limit: 10
95+
}) {
96+
content
97+
}
98+
}
99+
}
100+
----
101+
102+
103+
[[pagination-cursor-based]]
104+
== Cursor-based pagination
105+
106+
On relationship fields, you are able to take advantage of cursor-based pagination, which is often associated with infinitely-scrolling applications.
107+
108+
Using the following type definition:
109+
110+
[source, graphql, indent=0]
111+
----
112+
type User {
113+
name: String!
114+
posts: [Post!]! @relationship(type: "HAS_POST", direction: OUT)
115+
}
116+
117+
type Post {
118+
content: String!
119+
}
120+
----
121+
122+
If you wanted to fetch the posts of user "John Smith" 10 at a time, you would first fetch 10:
123+
124+
[source, graphql, indent=0]
125+
----
126+
query {
127+
users(where: { name: "John Smith" }) {
128+
name
129+
postsConnection(first: 10) {
130+
edges {
131+
node {
132+
content
133+
}
134+
}
135+
pageInfo {
136+
endCursor
137+
hasNextPage
138+
}
139+
}
140+
}
141+
}
142+
----
143+
144+
In the return value, if `hasNextPage` is `true`, you would pass `endCursor` into the next query of 10.
145+
You can do this with a variable, for example, `$after` in the following query:
146+
147+
[source, graphql, indent=0]
148+
----
149+
query Users($after: String) {
150+
users(where: { name: "John Smith" }) {
151+
name
152+
postsConnection(first: 10, after: $after) {
153+
edges {
154+
node {
155+
content
156+
}
157+
}
158+
pageInfo {
159+
endCursor
160+
hasNextPage
161+
}
162+
}
163+
}
164+
}
165+
----
166+
167+
You may continue until `hasNextPage` is `false` in the return - this is when you have reached the end of the data.
168+
169+
170+
=== `totalCount`
171+
172+
The Connection fields also offer a `totalCount` field which can be used to calculate page numbers.
173+
This is useful if you want to paginate by cursor but use page numbers in your application.
174+
175+
Add the `totalCount` field which returns the total number of results matching the filter used, for example:
176+
177+
[source, graphql, indent=0]
178+
----
179+
query Users($after: String) {
180+
users(where: { name: "John Smith" }) {
181+
name
182+
postsConnection(first: 10) {
183+
edges {
184+
node {
185+
content
186+
}
187+
}
188+
pageInfo {
189+
endCursor
190+
hasNextPage
191+
}
192+
totalCount
193+
}
194+
}
195+
}
196+
----

0 commit comments

Comments
 (0)