Count Queries in GraphQL

That would not really work or if it works then it would be similar to a DQL output which I believe is a bit unintuitive where the first object returns the count and next ones the actual data. As an example, the result of the DQL query

{
  directors(func: gt(count(director.film), 5)) {
    totalDirectors : count(uid)
    name@en
  }
}

is

{
  "data": {
    "directors": [
      {
        "totalDirectors": 7712
      },
      {
        "name@en": "Buster Keaton"
      },
      {
        "name@en": "Andrei Tarkovsky"
      }
...

I believe we should not go with this design.

In the design that @rajas is suggesting, the schema would be like below. It is a breaking change yes but has the pros that mentioned.

type QueryDataResponse {
  count: Int64
  data: [Data]
}

query {
  queryData(filter: DataFilter): QueryDataResponse
}

That is right but I don’t think we should disregard the first argument if count is given. That is also incompatible with how DQL works. If the user just wanted the complete count, they can always do a separate query without the first argument.

2 Likes