8

I am new to HotChocolate and I am seriously try to add aggregates like sum, average, count and etc. to my graphql backend. So, the frontend could query the aggregations without doing additional efforts on backend. something like hasura queries:

query {
  article_aggregate {
    aggregate {
      count
      sum {
        rating
      }
      avg {
        rating
      }
      max {
        rating
      }
    }
    nodes {
      id
      title
      rating
    }
  }
}

Can anyone help me?

Thank you!

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
  • 1
    At the moment you can extend the connection type and add aggregations. But this is something manual. Aggregations like in hasura are on our list for version 12. – Michael Ingmar Staib Feb 03 '21 at 13:50
  • @MichaelIngmarStaib Do you have an example on how we could do this with extending connection type? We are looking to do sum aggregates on the total data set prior to paging being applied. – TWilly Feb 09 '21 at 00:09
  • 1
    Found this github page.. https://github.com/ChilliCream/hotchocolate/discussions/2963 – TWilly Feb 09 '21 at 00:10
  • Essentially you can do ... ``` [ExtendObejctType("ArticleConnection")] public class ConnectionExtension { public SumAggregate GetSum() => .... } ``` – Michael Ingmar Staib Feb 12 '21 at 07:39

0 Answers0