Can graphql return aggregate counts?

前端 未结 5 1095
说谎
说谎 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:58

    This depends on whether you build the aggregator into your schema and are able to resolve the field.

    Can you share what kind of GraphQL Server you're running? As different languages have different implementations, as well as different services (like Hasura, 8base, and Prisma).

    Also, when you say "counts", I'm imagining a count of objects in a relation. Such as:

    query {
      user(id: "1") {
        name
        summaries {
          count
        }
      }
    }
    
    // returns
    {
      "data": {
        "user": {
          "name": "Steve",
          "summaries": {
            "count": 10
          }
        }
      }
    }
    

    8base provides the count aggregate by default on relational queries.

提交回复
热议问题