Postgraphile: Feature request: `groupBy` Queries support

Created on 19 Jun 2020  路  7Comments  路  Source: graphile/postgraphile

How complicated would it be to add a groupBy feature on connections?
I guess pretty complicated, but the value would be immense...
This is not something we can do on the client-side for large lists

Strapi seems to do it with this API

postsConnection {
  groupBy {
    published: {
      key
      connection {
        aggregate {
          avg {
            nb_likes
          }
        }
      }
    }
  }
}

https://strapi.io/blog/release-v3-alpha-14-graphql-aggregations-customization-security

馃攣 revisit-in-v5

Most helpful comment

Yeah this is done now; min/max/avg/stddev/variance/distinctCount/sum, groupBy multiple things, having filters, order by aggregates, add your own aggregates, add your own groupings, group derivatives (e.g. group by timestamp truncated to hour/day) with add your own too. Would love to know how you all get on with the above as I want to move it out of experimental status.

All 7 comments

Looking for this as well.

Wow good synchronization, I saw things moving there https://github.com/graphile/pg-aggregates/ !

Yeah this is done now; min/max/avg/stddev/variance/distinctCount/sum, groupBy multiple things, having filters, order by aggregates, add your own aggregates, add your own groupings, group derivatives (e.g. group by timestamp truncated to hour/day) with add your own too. Would love to know how you all get on with the above as I want to move it out of experimental status.

Thanks for the links @crubier; I think ours are more powerful than all of the above 馃檶

I should have mentioned above that the aggregates work over both regular columns and computed column functions, and you can also group by computed column functions too 馃殌

Is my "own groupings" the way to go for the equivalent of ARRAY_AGG?

It'd be an aggregate rather than a grouping for array_agg; see: https://github.com/graphile/pg-aggregates/blob/cceccbb1884c09d8bce308ab79a947f8ef5257a8/src/AggregateSpecsPlugin.ts#L46 your pgTypeAndModifierModifier would have to specify a PG array type for the relevant incoming type. Please file questions about @graphile/pg-aggregates on the pg-aggregates repo.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

5argon picture 5argon  路  4Comments

outsidenote picture outsidenote  路  4Comments

WestleyArgentum picture WestleyArgentum  路  3Comments

giacomorebonato picture giacomorebonato  路  3Comments

srghma picture srghma  路  3Comments