Add @count to GraphQL schemas and queries

Moved from GitHub dgraph/5529

Posted by ScottWallace:

Experience Report

We are using a hybrid of a GraphQL schema, mutations in GraphQL, and queries in GraphQL+. This allows us to use @count in queries, but still use the ease of GraphQL mutations and schema creation. We use the dashboard to recreate count indexes after schema updates.

What you wanted to do

We would like to use the @count directive in our GraphQL schemas, and have it create count indexes. Counts are integral to our effort, not just for display to the user, but also in queries that include var math to create weighted values for sorting. As a second priority, we would like to have count supported in GraphQL queries, but the index creation is most important to us.

What you actually did

We’ve considered taking the effort to create standard (non-GraphQL) schemas, but want to know if @count is on the list of enhancements and when it might arrive, rather than change out our schema and all the testing associated with it.

Why that wasn’t great, with examples

We re-create count indexes after each schema change. A trivial task, but could be risky once we enter a live environment. We use GraphQL+ in queries in order to pick up the count feature, but would enjoy staying with just GraphQL for all data access.

ScottWallace commented :

Got my invite for slash graphql, looks great, but we can’t really take advantage of it without this feature.

amaster507 commented :

This is pretty high on our feature request list too! Right now in order to do proper pagination in a UI we need total count. The only way to get a total count is to run the query twice. Once get all ids ad the root level with any required fields to appeace @cascade to be similar in data to second query. Then with the second query get the actual data we want with first and offset parameters.

lcasassa commented :

Looking forward to other aggregations like sum too