Retrieve all predicates of all nodes

Hi Devs,

I want to retrieve all predicates of all nodes. I know that I can do this with

{
  result (func: has(dgraph.type)) {
    uid
    expand(_all_) {
      uid
    }
  }
}

However, this requires all nodes to have a dgraph.type in order for expand to work. Is there any way of retrieving all triples without the requirement of having all nodes have a type?

One alternative that exists is explicitly stating the predicates:

{
  prop as var(func: has(prop))
  edge as var(func: has(edge))
  
  result (func: uid(prop,edge)) {
    uid
    prop
    edge { uid }
  }
}

But for a huge schema this requires many queries. Is there another way you can think of?

Yep, there is a “hack” (not sure if it still works). You can create a “dummy” type in Dgraph with all possible edges. And you gonna use:

{
  result(func: has(anyPred)) {
    uid
    expand(MyDummyType) {
      uid
      expand(MyDummyType)
    }
  }
}

This is useful for datasets that you don’t know the structure and wanna create the Schema Type.

I presume this returns only uids that have anyPred, so I need a “seed” predicate that all nodes have like xid or dgraph.type. I’ll give it a try with my 235k predicates schema :smiley:

Hehehe, curious as to what are you modelling? Want to brainstorm if that the best way to model.