Count Queries in GraphQL

That’s great news!

However I’m missing an __aggregate field like in the following example:

queryPosts {
   __aggregate {
      count
   }
}

With the current implementation I can only do:

getUser(id: $userId) {
   postsAggregate {
      count
   }
}

which is problematic because it makes counting filtered queries hard. E.g. counting only posts with certain properties would include use of @cascade and forces me to return unwanted data (e.g. id of posts).

getUser(id: $userId) @cascade {
   posts(filter: {
      likes: {gt: 10}
   }) {
      id
   }
   postsAggregate {
      count
   }
}

After all, the goal of dedicated count queries is speed. Otherwise I could just query all IDs by myself and count on client-side.

2 Likes