Skip to content

Commit 18edfb3

Browse files
authored
Merge pull request #255 from neo4j/apply-filter-page-changes-to-6.x
apply filter page changes to 6.x
2 parents 8ed95a6 + 4120de8 commit 18edfb3

File tree

12 files changed

+207
-193
lines changed

12 files changed

+207
-193
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
- A xref::getting-started/toolbox.adoc[Toolbox] (UI) to experiment with your Neo4j GraphQL API on Neo4j Desktop.
3535

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/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: 185 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,185 @@
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 @node {
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(limit: 10) {
32+
name
33+
}
34+
}
35+
----
36+
37+
And then on subsequent calls, introduce the `offset` argument and increment it by 10 on each call.
38+
39+
Fetch the second page with:
40+
41+
[source, graphql, indent=0]
42+
----
43+
query {
44+
users(offset: 10, limit: 10) {
45+
name
46+
}
47+
}
48+
----
49+
50+
Fetch the third page with:
51+
52+
[source, graphql, indent=0]
53+
----
54+
query {
55+
users(offset: 20, limit: 10) {
56+
name
57+
}
58+
}
59+
----
60+
61+
And so on.
62+
63+
64+
=== Total number of pages
65+
66+
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.
67+
This determines what the last page is, and whether there is a next page.
68+
69+
See xref::queries-aggregations/queries.adoc[Count] queries for details on how to execute these queries.
70+
71+
72+
=== Paginating relationship fields
73+
74+
Say that in addition to the `User` type above, there is also a `Post` type which a `User` has many of.
75+
You can also fetch a `User` and then paginate through their posts:
76+
77+
[source, graphql, indent=0]
78+
----
79+
query {
80+
users(where: {
81+
name_EQ: "Billy"
82+
}) {
83+
name
84+
posts(offset: 20, limit: 10) {
85+
content
86+
}
87+
}
88+
}
89+
----
90+
91+
92+
[[pagination-cursor-based]]
93+
== Cursor-based pagination
94+
95+
On relationship fields, you are able to take advantage of cursor-based pagination, which is often associated with infinitely-scrolling applications.
96+
97+
Using the following type definition:
98+
99+
[source, graphql, indent=0]
100+
----
101+
type User @node {
102+
name: String!
103+
posts: [Post!]! @relationship(type: "HAS_POST", direction: OUT)
104+
}
105+
106+
type Post @node {
107+
content: String!
108+
}
109+
----
110+
111+
If you wanted to fetch the posts of user "John Smith" 10 at a time, you would first fetch 10:
112+
113+
[source, graphql, indent=0]
114+
----
115+
query {
116+
users(where: { name_EQ: "John Smith" }) {
117+
name
118+
postsConnection(first: 10) {
119+
edges {
120+
node {
121+
content
122+
}
123+
}
124+
pageInfo {
125+
endCursor
126+
hasNextPage
127+
}
128+
}
129+
}
130+
}
131+
----
132+
133+
In the return value, if `hasNextPage` is `true`, you would pass `endCursor` into the next query of 10.
134+
You can do this with a variable, for example, `$after` in the following query:
135+
136+
[source, graphql, indent=0]
137+
----
138+
query Users($after: String) {
139+
users(where: { name_EQ: "John Smith" }) {
140+
name
141+
postsConnection(first: 10, after: $after) {
142+
edges {
143+
node {
144+
content
145+
}
146+
}
147+
pageInfo {
148+
endCursor
149+
hasNextPage
150+
}
151+
}
152+
}
153+
}
154+
----
155+
156+
You may continue until `hasNextPage` is `false` in the return - this is when you have reached the end of the data.
157+
158+
159+
=== `totalCount`
160+
161+
The Connection fields also offer a `totalCount` field which can be used to calculate page numbers.
162+
This is useful if you want to paginate by cursor but use page numbers in your application.
163+
164+
Add the `totalCount` field which returns the total number of results matching the filter used, for example:
165+
166+
[source, graphql, indent=0]
167+
----
168+
query Users($after: String) {
169+
users(where: { name_EQ: "John Smith" }) {
170+
name
171+
postsConnection(first: 10) {
172+
edges {
173+
node {
174+
content
175+
}
176+
}
177+
pageInfo {
178+
endCursor
179+
hasNextPage
180+
}
181+
totalCount
182+
}
183+
}
184+
}
185+
----

modules/ROOT/pages/queries-aggregations/pagination/cursor-based.adoc

Lines changed: 0 additions & 91 deletions
This file was deleted.

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

Lines changed: 0 additions & 9 deletions
This file was deleted.

0 commit comments

Comments
 (0)