Dgraph Type query

Hi,I want to query some type of information。For example, If I want to query the number of ‘process’ types, how do I do that?

{
all(func: type(“process”)) {
uid
}

That doesn’t capture any information

{
all(func: eq(dgraph.type, process)) {
expand(all) { u as uid }
}
result(func:uid(u)){
count(uid)
}
}

The query below counts the number of objects of type “Process”.

{
  query(func: has(<dgraph.type>)) @filter(eq(<dgraph.type>, "Process")) {
    count(uid)
  }
}
2 Likes

Many thanks for you! But I want to query for a certain type of node, a child node is a certain type of number or information.For example, I want to query for information about a certain type of node that the specified Topic node points to.

{
all(func: eq(topic, “general”)){
topic
related@filter(eq(<dgraph.type>, “process”)) {
uid
question
}
}
}

Hi @Soultrans, assuming that there is a type Topics with a predicate topicQn pointing to either type Qn or Qn1 (similar to process in your example), following query will help.

  • For finding topicQn pointing to Qn
{
  qn as var(func: type(Qn))
  query(func: type(Topics) ) @cascade {
    uid
    topicName
    count(topicQn)
    topicQn @filter(uid(qn)){
      qn
    }
  }
}

For finding topicQn pointing to Qn1, just replace Qn with Qn1 in the var section.

Your help was very much appreciated.

1 Like

Hi @Soultrans, you are welcome! I request you to select the response and mark it as solved, so that other community members can directly view the solution when they search for the same issue.

Ok, I will reply after try.