Aggregation
FastGQL auto extends the schema using the @generate
directive to add aggregation queries to the extended types. Aggregation results can be accessed using the _[fieldName]Aggregate
field in the GraphQL query.
FastGQL supports the following aggregation operations: count
, sum
, avg
, min
, max
.
Count Aggregate
Aggregate Filter
Similar to filter queries we can filter our aggregate queries to returned different results. The following example will count all posts that have a category with the id == 1
.
Group By
Group by is used to group the results based on the given field. The following example will group all posts based on the NAME
and return the count of posts in each group.
We can GroupBy multiple fields by providing an array of fields, or a single field. The group field will be an object with the grouped fields as keys.