Conditional Query Statement

I am not sure your programming language of choice or requirements, but if your requirements are you must have two queries made at the same commit level (read timestamp) then you could make a read-only transaction and make both queries from that (the second being conditional of the first).

If you have a requirement of exactly one network request for some reason, you might be able to try

{
  q1(func: has(namex),first:1){x1 as uid}
  q2(func: has(name),first:1) @filter(eq(len(x1),0)) {uid}
}

where you will get q1 only, unless its empty, then you will get q2 only.

3 Likes