Count Queries in GraphQL

Aggregate Queries at root and child levels have been pushed to master. We will soon be updating related documentation.
Related PRs: Feat(GraphQL): Add aggregate query at root level by vmrajas · Pull Request #6985 · dgraph-io/dgraph · GitHub , Feat(GraphQL): Add Aggregation Queries at Child Level by vmrajas · Pull Request #7022 · dgraph-io/dgraph · GitHub .

Note that Aggregate Queries (min, max, sum, avg) are not going to be part of 20.11 .
Count Queries are going to be part of 20.11

1 Like

Is it possible to get a count that doesn’t match a node? example:

postsAggregate(filter: {not: {user: "0x1234"}}) {
  count
}

Currently, with my schema and in the UI, nodes aren’t in the available to filter list.

Yes, its possible.

Example:
For the schema,

type Post {                                                                     
    id: ID!                                                                     
    title: String! @search                                                      
    text: String                                                                
}                                                                               
                                                                                
type Author {                                                                   
    id: ID!                                                                     
    name: String! @search                                                       
    posts: [Post!]                                                              
} 

The following query will show for all authors, the count of posts which are not equal to "0x2" ,

query{
  queryAuthor{
    postsAggregate(filter:{not:{id:["0x2"]}}){
      count
    }
  }
}
1 Like