Understanding dynamic aggregate order_by
, and alternatives
#9593
-
Hello! I am struggling to order my results the way I'd like to. I have I'm currently close - there's an existing computed field query getProduct($url: String!) {
product_reviews(
where: {product: {url: {_eq: $url}}
order_by: {relevant_attributes_aggregate: {count: desc}}
) {
...review
}
} however what I need is a dynamic computed field that takes the user ID, such that I can work out on the fly which attributes are shared, something like query getProduct($url: String!, $userId: Int!) {
product_reviews(
where: {product: {url: {_eq: $url}}
order_by: {shared_attributes_aggregate({args: {userId: $userId}}): {count: desc}}
) {
...review
}
} Which I appreciate is entirely not a thing, but hopefully it illustrates well enough what I'm aiming for. I think this must be a common use case, however I really can't work out how to manage it - as I understand it, no version of this approach is currently possible. I'm wondering if anyone has ideas on how to make it work, either straightforwardly, or advice on using further views and computed fields to get the sort functionality I need. I would also love to keep the returned |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
I have addressed this by:
it feels like a long way round, although I'm actually quite pleased with the separation of concerns whilst maintaining the option to use parameters in my query |
Beta Was this translation helpful? Give feedback.
I have addressed this by:
review_id
andreviews.id
, such that traversing the graph (e.g. for filtering) is still possible nested by one more level, e.g. before I had(where: {rating: {_gt: 3}})
now I have(where: {review: {rating: {_gt: 3}}})
it feels like a long way round, although I'm actually quite pleased with the separation…