Can graphql return aggregate counts?

前端 未结 5 1185
说谎
说谎 2021-02-03 16:58

Graphql is great and I\'ve started using it in my app. I have a page that displays summary information and I need graphql to return aggregate counts? Can this be done?

5条回答
  •  感情败类
    2021-02-03 17:33

    You would define a new GraphQL type that is an object that contains a list and a number. The number would be defined by a resolver function.

    On your GraphQL server you can define the resolver function and as part of that, you would have to write the code that performs whatever calculations and queries are necessary to get the aggregate counts.

    This is similar to how you would write an object serializer for a REST API or a custom REST API endpoint that runs whatever database queries are needed to calculate the aggregate counts.

    GraphQL's strength is that it gives the frontend more power in determining what data specifically is returned. Some of what you write in GraphQL will be the same as what you would write for a REST API.

提交回复
热议问题