Hello,
I'm having an issue while using order_by on aggregate fields.
{
author (order_by: {articles_aggregate: { count: desc }}) {
id
name
articles_aggregate(where: $where) {
aggregate {
count
}
}
}
}
It looks like the SQL query doesn't apply the filter used in the aggregated count on the order_by count. Am I doing something wrong?
@rafaelugolini This is currently the expected behavior. The filters used on *_aggregate fields in the query are not applied at the top level. For example, you can have such a query:
{
author (order_by: {articles_aggregate: { count: desc }}) {
id
name
count1: articles_aggregate(where: $where1) {
aggregate {
count
}
}
count2: articles_aggregate(where: $where2) {
aggregate {
count
}
}
}
}
In this case, we wouldn't know which filter to apply at the top level.
Your use case however is very valid. Maybe we can extend the order_by syntax to allow specifying the where clause?
{
author (order_by: {articles_aggregate: { where: $where using: {count: desc} }) {
id
name
articles_aggregate(where: $where) {
aggregate {
count
}
}
}
}
@0x777 that would work 馃憤
btw thanks for the awesome response time, I 鉂わ笍 hasura
hi @rafaelugolini : I'm facing the same issue like yours. How did you solve that?
@hoanv810 hey :) from what I remember we created a view
This is definitely a feature we could use. Hopefully once 1.0 is out things like this can get looked at for a future roadmap.
Any news on this ?
I am working with custom reports where the filters are quite dynamic and it is not possible to solve my case with views.
Having the possibility to add where filter to the order_by clause like @0x777 mentioned would solve this perfectly.
Hi, any news, ETA on this? Hasura is terrific, but the lacks of this feature (as suggested from @0x777 would be great) breaks all our server side pagination/reorder, thus preventing us from be able to deploy with large datasets...
Thank you in advance
Most helpful comment
@rafaelugolini This is currently the expected behavior. The filters used on
*_aggregatefields in the query are not applied at the top level. For example, you can have such a query:In this case, we wouldn't know which filter to apply at the top level.
Your use case however is very valid. Maybe we can extend the
order_bysyntax to allow specifying thewhereclause?