Expand description
Aggregate types.
Every table gets a second root field alongside its rows:
author_aggregate(where: {id: {_gt: 2}}) {
aggregate { count, avg { salary }, max { salary } }
nodes { id name }
}nodes is the same list the plain root field returns, so one request can
ask for a page of rows and the count of the whole set the page came from –
which is the query behind every “showing 1-25 of 380” in a user interface,
and the reason the two live under one field instead of two.
Which functions a column gets follows from what PostgreSQL will accept.
sum and avg are offered on numeric columns only; max and min on
anything that orders, which includes text and timestamps. Offering avg
over a text column would put an error in the schema rather than in the
client.
Enums§
- Returns
- What an aggregate’s field is typed as.
Constants§
- NUMERIC_
AGGREGATES - Aggregates over numbers, and the GraphQL type each returns.
- ORDERED_
AGGREGATES - Aggregates over anything that orders.
Functions§
- aggregate_
fields_ type_ name - The name of a table’s aggregate-function type.
- aggregate_
type_ name - The name of a table’s aggregate root type.
- field_
type_ for - The GraphQL type name for one column under one aggregate.
- function_
fields_ type_ name - The name of the type holding one aggregate’s per-column results.
- functions_
for - The columns each aggregate function applies to, for one table.
- is_
incrementable - Whether a column can be added to.
- is_
numeric - Whether a column can be summed and averaged.
- is_
ordered - Whether a column can be ranked, which is what
maxandminneed. - tables
- Which tables get aggregate types.