@@ -34,13 +34,32 @@ For which the following query fields are generated:
34
34
----
35
35
type Query {
36
36
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 !
38
38
39
39
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 !
41
41
}
42
42
----
43
43
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
+
44
63
== Aggregation fields
45
64
46
65
Based on the type definitions, here is a list of fields that accept aggregations supported by Neo4j GraphQL:
56
75
[source, graphql, indent=0]
57
76
----
58
77
query {
59
- usersAggregate {
60
- name {
61
- longest
78
+ usersConnection {
79
+ aggregate {
80
+ name {
81
+ longest
82
+ }
62
83
}
63
84
}
64
85
}
65
86
----
66
87
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
- ----
81
88
82
89
| Temporal (e.g. `DateTime`, `Time`, `LocalTime`, `LocalDateTime`, `Duration`)
83
90
| `min`, `max`
86
93
[source, graphql, indent=0]
87
94
----
88
95
query {
89
- postsAggregate {
90
- createdAt {
91
- min
96
+ postsConnection {
97
+ aggregate {
98
+ createdAt {
99
+ min
100
+ }
92
101
}
93
102
}
94
103
}
95
104
----
96
105
|===
97
106
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.
109
107
110
108
.Counting User nodes
111
109
[source, graphql, indent=0]
112
110
----
113
111
query {
114
- usersAggregate {
115
- count
112
+ usersConnection {
113
+ aggregate {
114
+ count {
115
+ nodes
116
+ }
117
+ }
116
118
}
117
119
}
118
120
----
@@ -121,20 +123,38 @@ query {
121
123
[source, graphql, indent=0]
122
124
----
123
125
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
+ }
126
132
}
127
133
}
128
134
----
129
135
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
+
130
146
.Counting all posts per User
131
147
[source, graphql, indent=0]
132
148
----
133
149
query {
134
150
users {
135
151
id
136
- postsAggregate {
137
- count
152
+ postsConnection {
153
+ aggregate {
154
+ count {
155
+ nodes
156
+ }
157
+ }
138
158
}
139
159
}
140
160
}
@@ -148,10 +168,12 @@ By using the `node` field, related nodes properties can be aggregated:
148
168
query {
149
169
users {
150
170
name
151
- postsAggregate {
152
- node {
153
- content {
154
- longest
171
+ postsConnection {
172
+ aggregate {
173
+ node {
174
+ content {
175
+ longest
176
+ }
155
177
}
156
178
}
157
179
}
@@ -163,17 +185,36 @@ query {
163
185
164
186
Relationship properties can be aggregated as well by using the `edge` field:
165
187
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
+
166
205
.Querying what User nodes posted up to a date
167
206
[source, graphql, indent=0]
168
207
----
169
208
query {
170
209
users {
171
210
name
172
- postsAggregate {
173
- edge {
174
- date {
175
- max
176
- }
211
+ postsConnection {
212
+ aggregate {
213
+ edge {
214
+ date {
215
+ max
216
+ }
217
+ }
177
218
}
178
219
}
179
220
}
0 commit comments