Aggregate Table Computed Fields #8864
Unanswered
gjacobrobertson
asked this question in
Question
Replies: 1 comment 3 replies
-
I have another circumstance, where we have a computed |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Is your proposal related to a problem?
I am having difficulty aggregating over indirect relationships, Take for example the following schema:
with each table tracked and foreign key exposed as an object and corresponding array relationship.
The generated GQL schema can aggregate ratings by article, e.g.
but as is, there is no way to query of the form "For each author, return their average rating across all articles they have written"
Describe the solution you'd like
It would be useful if
_aggregate
fields were generated corresponding to Table Computed Fields, since Table Computed Fields can be used to express denormalized relationships, e.g.And create a computed field
authors.article_ratings
from that function.The desired aggregation could be expressed in GQL as
Given that Custom Functions returning
SETOF
tables get exposed root-level aggregate fields (https://hasura.io/docs/latest/graphql/core/databases/postgres/schema/custom-functions/#aggregations-on-custom-functions), and Table Computed Fields are otherwise exposed similarly to array relationships (they acceptwhere
,limit
,order_by
, etc clauses), it seems reasonable that Table Computed Fields could be aggregated.Describe alternatives you've considered
I have considered an alternative approach of using views to express denormalized relationships, e.g.
Where one could track a
author.article_ratings
field as a plain array relationship. This seems feasible but adds complexity to schema definition and maintenance. It's great to be able to express denormalized relationships as Table Custom Fields without impact on table/view definition.If the feature is approved, would you be willing to submit a PR?
No, at least not in the near future.
Beta Was this translation helpful? Give feedback.
All reactions