Query according to type classification, and statistics

$ dgraph version
V20.03

What you wanted to do

I want to query according to the classification of <dgraph.type>,and count the number under each category

What you actually did

Please excuse my poor GraphQL, I can’t get any information, may I ask how to write ?

{
   var(func:has(dgraph.type)){
    <dgraph.type> @groupby(<dgraph.type>){
      a as count(uid)
    }
  }
    
  Classification(func:uid(a)){
    <dgraph.type>
    tota:val(a)
  }
 }

The error message is as follows:

Error Name: t
Message: : context deadline exceeded
Raw Error:

{
  "name": "t",
  "url": "http://0.0.0.000:8080/query?timeout=20s&debug=true",
  "errors": [
    {
      "message": ": context deadline exceeded",
      "extensions": {
        "code": "ErrorInvalidRequest"
      }
    }
  ]
}

Who can help me? :rofl:

Hi @Soultrans
First thing you need to know is that there is a different between dql and GraphQL. The query that you wrote is a dql(Dgraph Query Language). You can execute dql queries using Ratel. Take a look at this tuturial: Dgraph tutorials series - 1: Getting started - Dgraph Blog
The query you need to execute to get this information is something like this:

{
  getTypes(func: has(dgraph.type)) @groupby(dgraph.type) {
    count(uid)
  }
}

Also the error you got is because your query execution took more than 20 second which is the default query timeout in Ratel and you can see 20s in the url you pasted there.

1 Like