Aggregations
Based on the given type definitions, here is a list of fields that accept aggregations supported by Neo4j GraphQL:
Type | Aggregating function | Example |
---|---|---|
String (e.g. |
|
Longest User name
|
Numeric (e.g. |
|
Example query
|
Temporal (e.g. |
|
First Post date
|
The argument |
Aggregate related nodes
Related nodes can also be aggregated within a query by accessing the aggregation fields in the node. In these fields, you can count, aggregate the nodes or edges fields.
The same selections and types as before are available in relationship aggregations.
query {
usersAggregate {
count
}
}
query {
usersAggregate(where: { name_STARTS_WITH: "J" }) {
count
}
}
query {
users {
id
postsAggregate {
count
}
}
}
By using the node
field, related nodes properties can be aggregated:
query {
users {
name
postsAggregate {
node {
content {
longest
}
}
}
}
}
Aggregate relationships
Relationship properties can be aggregated as well by using the edge
field:
query {
users {
name
postsAggregate {
edge {
date {
max
}
}
}
}
}
When performing an aggregation on related nodes, the query against the relationship
can be defined as "undirected" by using the argument directed: false
:
query {
users {
id
postsAggregate(directed: false) {
count
}
}
}