graphql-spqr
graphql-spqr copied to clipboard
Aggregate syntax question
I've been digging into how to implement aggregates for a single type in my project and here is an example I've found that seems pretty reasonable however I'm at a loss as to how to take the "fields" such as rating as an input for the "aggregate". Could I get a hint as to the approach for this?
author (where: {id: {_eq: 1}}) {
id
name
articles_aggregate {
aggregate {
count
avg {
rating
}
max {
rating
}
}
articles {
id
title
rating
}
}
}
}
Take a look at the way Prisma (https://www.prisma.io/) handles this.
TL;DR: Create fields such as rating_count
, rating_avg
, and rating_max
, and treat them just like normal fields backed by resolver logic. GraphQL as a standard, and the tools built around it seem to want nothing to do with aggregation, I've found.