Graphql-engine: order_by aggregated fields don't use filter

Created on 9 Jan 2019  路  7Comments  路  Source: hasura/graphql-engine

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?

1039

1042

server hard enhancement medium triag2-needs-rfc

Most helpful comment

@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
        }
    }      
  }
}

All 7 comments

@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

Was this page helpful?
0 / 5 - 0 ratings

Related issues

EmrysMyrddin picture EmrysMyrddin  路  3Comments

hooopo picture hooopo  路  3Comments

Fortidude picture Fortidude  路  3Comments

macalinao picture macalinao  路  3Comments

bogdansoare picture bogdansoare  路  3Comments