7

Is it possible in GraphQL or Hasura to group the results by month or year? I'm currently getting the result list back as a flat array, sorted by the date attribute of the model. However, I'd like to get back 12 subarrays corresponding to each month of the year.

7ball
  • 2,183
  • 4
  • 26
  • 61

1 Answers1

3

From docs - natively not supported.

Derived data or data transformations leads to views. Using PostgreSQL EXTRACT Function you can have separate month field from data ... but still as flat array.

Probably with some deeper customization you can achieve desired results ... but graphql [tree, arrays] structures are more for embedding not for view ...

How many records you're processing? Hundreds? Client side conversion (done easily from apollo client data on react component/container [view] level) may be good enough [especially with extracted month field].

PS. You can have many results groupped in arrays if you 'glue' many queries (copies, each month filtered) on top level ... but probably not recommended solution.

xadm
  • 8,219
  • 3
  • 14
  • 25