How to find nodes without dgraph.type?

I had some bad data when importing using live loader (my fault). I need to delete all of the relations to these empty nodes. The only thing they contain is a uid. They were not specified a dgraph.type or any other properties as I mistyped their blank node in the script.

How can I find nodes that only have a uid and nothing else? I know it will be bad performance, but it will not be a frequent query.

I tried:

query {
  node(func: has(uid)) @filter(NOT has(dgraph.type)) {
    uid
  }
}

But that gives me:

errors… while converting to subgraph: Argument cannot be “uid”

So how else could this be done?

There’s no easy way, only this one:

query {
  va1 as var(func: has(pred1))
  va2 as var(func: has(pred2))
  va3 as var(func: has(pred3))
  va4 as var(func: has(pred4))
  va5 as var(func: has(pred5))
  va6 as var(func: has(pred6))
  va7 as var(func: has(pred7))
  
  node(func: uid(va1,va2,va3,va4,va5,va6,va7)) 
    @filter(NOT has(dgraph.type)) {
    uid
  }
}

what does pred* mean? Is it just saying has the first predicate, has the second predicate? Where is it getting these predicates from?

Not sure if I got your question. This query is an example of a fixed query. The preds have to be manually added to the query. There’s no way, as far as I know, to do it automatically.

As has() func doesn’t support multiple predicates as params or variables with predicates. You have to manually add it.

but my nodes don’t have any predicates. They are basically just an empty node with uid only. There are other nodes that have them as children and I need to delete them globally to resolve grpahql errors with missing required fields when it links to these empty nodes.

Oh, you wanna find “empty nodes”. From the way you said it, I thought you wanted any nodes with some information. So in your case, you wanna find “dangling empty nodes”.

You can try with reverse

query {
  va1 as var(func: has<(~pred1>))
  va2 asvar(func: has(<~pred2>))
 
  node(func: uid(va1,va2)) @filter(NOT has(dgraph.type)) {
    uid
  }
}

Or query for the parent node and collect only those children who don’t have dgraph.type.

3 Likes

This is what I will have to do. Thank you.

After writing the upsert I had to do it this way anyways, because the delete * P O is invalid syntax.

1 Like