GraphQLize supports the standard aggregate functions
avg. We can also use the
GROUP-BY operation along with these aggregate functions.
The aggregate functions over columns are available as
fields in the corresponding
type representing the table.
As seen in the above example, GraphQLize uses the name of the aggregate function (in camel case) along with the preposition
Of as prefix to represent the aggregate functions as fields.
|Column Name||Aggregate Function||Field|
Aggregates Over Relationships
We can use the aggregate functions over the relationship fields as well.
Let's assume that we have a schema like below
We can get the total courses count and the average course rating of all the authors along with their first-name and last-name, using the following GraphQL query
countOfId field translates to
count(id) in the SQL's select clause. The count of all rows via
count(*) will be added in a future release.
The aggregate functions often paired along with the GROUP BY operation and GraphQLize supports it out of the box!
For the above schema, we can group the courses by their rating and get their count using the following query