Skip to main content

Module aggregate

Module aggregate 

Source
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 max and min need.
tables
Which tables get aggregate types.