hasura / hasura/graphql-engine
Support aggregation queries on computed fields for order_by
- Dominant language
- TypeScript
- Stars
- 32.1k
- Forks
- 3k
- PR merge metrics
- PR metrics pending
Description
### Is your proposal related to a problem?
In v2.27, Aggregation queries for computed fields where added ([blog post](https://hasura.io/blog/introducing-aggregation-queries-for-computed-fields/)). This is an awesome improvement! However, while migrating an actual column to a computed field, I noticed that one feature was still missing: the ability to sort results using aggregation queries on computed fields.
Let's consider a similar query to the one on the blog post where we would list the authors with their average word count per article:
```gql
query {
users {
name
articles_aggregate {
aggregate {
avg {
word_count
}
}
}
}
}
```
if `word_count` **was not** a computed field, we could sort the users list by their average word count per article:
```gql
query {
users(order_by: {
articles_aggregate: {
avg: {
word_count: asc
}
}
}) {
name
articles_aggregate {
aggregate {
avg {
word_count
}
}
}
}
}
```
This is not possible as soon as `word_count` is a computed field.
### Describe the solution you'd like
Allow using aggregate on computed fields for `order_by` conditions.
Contributor guide
Research direction
Start by tracing the GraphQL aggregation and order_by paths represented by the query examples, focusing on how computed fields are handled in each. Done means users can sort with aggregate order_by conditions when the aggregated field is computed, while the shown aggregation query continues to work.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- graphql, typescript
- Domain
- api
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100