Skip to content

Commit 6c1bec5

Browse files
angrykoalarsill-neo4j
authored andcommitted
Merge pull request #239 from neo4j/update-6-aggregate
Update aggregate documentation for 6.x
1 parent b67f4b8 commit 6c1bec5

File tree

1 file changed

+89
-48
lines changed

1 file changed

+89
-48
lines changed

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

Lines changed: 89 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,32 @@ For which the following query fields are generated:
3434
----
3535
type Query {
3636
posts(where: PostWhere, sort: [PostSort!]!, limit: Int, offset: Int,): [Post!]!
37-
postsAggregate(where: PostWhere): PostAggregationSelection!
37+
postsConnection(after: String, first: Int, sort: [PostSort], where: PostWhere): PostsConnection!
3838
3939
users(where: UserWhere, sort: [UserSort!]!, limit: Int, offset: Int,): [User!]!
40-
usersAggregate(where: UserWhere): UserAggregationSelection!
40+
usersConnection(after: String, first: Int, sort: [UserSort], where: UserWhere): UsersConnection!
4141
}
4242
----
4343

44+
== Querying aggregations
45+
46+
Aggregations on a type are provided in the field `aggregate` inside Connection:
47+
48+
[source, graphql, indent=0]
49+
----
50+
query {
51+
usersConnection {
52+
aggregate {
53+
name {
54+
longest
55+
}
56+
}
57+
}
58+
}
59+
----
60+
61+
62+
4463
== Aggregation fields
4564

4665
Based on the type definitions, here is a list of fields that accept aggregations supported by Neo4j GraphQL:
@@ -56,28 +75,16 @@ a|
5675
[source, graphql, indent=0]
5776
----
5877
query {
59-
usersAggregate {
60-
name {
61-
longest
78+
usersConnection {
79+
aggregate {
80+
name {
81+
longest
82+
}
6283
}
6384
}
6485
}
6586
----
6687

67-
| Numeric (e.g. `Int`, `Float`, `BigInt`)
68-
| `min`, `max`, `average`, `sum`
69-
a|
70-
.Example query
71-
[source, graphql, indent=0]
72-
----
73-
query {
74-
usersAggregate {
75-
age {
76-
average
77-
}
78-
}
79-
}
80-
----
8188

8289
| Temporal (e.g. `DateTime`, `Time`, `LocalTime`, `LocalDateTime`, `Duration`)
8390
| `min`, `max`
@@ -86,33 +93,28 @@ a|
8693
[source, graphql, indent=0]
8794
----
8895
query {
89-
postsAggregate {
90-
createdAt {
91-
min
96+
postsConnection {
97+
aggregate {
98+
createdAt {
99+
min
100+
}
92101
}
93102
}
94103
}
95104
----
96105
|===
97106

98-
[NOTE]
99-
====
100-
The argument `where` can also be used in aggregation queries for xref::queries-aggregations/filtering.adoc[filtering] data.
101-
====
102-
103-
== Aggregate related nodes
104-
105-
Related nodes can also be aggregated within a query by accessing the aggregation fields in the node.
106-
In these fields, you can **count**, aggregate the **nodes** or **edges** fields.
107-
108-
The same selections and types as before are available in relationship aggregations.
109107

110108
.Counting User nodes
111109
[source, graphql, indent=0]
112110
----
113111
query {
114-
usersAggregate {
115-
count
112+
usersConnection {
113+
aggregate {
114+
count {
115+
nodes
116+
}
117+
}
116118
}
117119
}
118120
----
@@ -121,20 +123,38 @@ query {
121123
[source, graphql, indent=0]
122124
----
123125
query {
124-
usersAggregate(where: { name_STARTS_WITH: "J" }) {
125-
count
126+
usersConnection(where: { name_STARTS_WITH: "J" }) {
127+
aggregate {
128+
count {
129+
nodes
130+
}
131+
}
126132
}
127133
}
128134
----
129135

136+
137+
== Aggregating related nodes
138+
139+
You can aggregate related nodes in a query by accessing the aggregation fields in the connection.
140+
In these fields, you can **count**, aggregate the **nodes** or **edges** fields.
141+
142+
The same selections and types as in xref:#_aggregation_fields[] are available in relationship aggregations.
143+
144+
145+
130146
.Counting all posts per User
131147
[source, graphql, indent=0]
132148
----
133149
query {
134150
users {
135151
id
136-
postsAggregate {
137-
count
152+
postsConnection {
153+
aggregate {
154+
count {
155+
nodes
156+
}
157+
}
138158
}
139159
}
140160
}
@@ -148,10 +168,12 @@ By using the `node` field, related nodes properties can be aggregated:
148168
query {
149169
users {
150170
name
151-
postsAggregate {
152-
node {
153-
content {
154-
longest
171+
postsConnection {
172+
aggregate {
173+
node {
174+
content {
175+
longest
176+
}
155177
}
156178
}
157179
}
@@ -163,17 +185,36 @@ query {
163185

164186
Relationship properties can be aggregated as well by using the `edge` field:
165187

188+
.Counting edges between posts and users
189+
[source, graphql, indent=0]
190+
----
191+
query {
192+
users {
193+
id
194+
postsConnection {
195+
aggregate {
196+
count {
197+
edges
198+
}
199+
}
200+
}
201+
}
202+
}
203+
----
204+
166205
.Querying what User nodes posted up to a date
167206
[source, graphql, indent=0]
168207
----
169208
query {
170209
users {
171210
name
172-
postsAggregate {
173-
edge {
174-
date {
175-
max
176-
}
211+
postsConnection {
212+
aggregate {
213+
edge {
214+
date {
215+
max
216+
}
217+
}
177218
}
178219
}
179220
}

0 commit comments

Comments
 (0)