How to set func to null

To facilitate better answering of questions, if you have a question, please fill in the following questions. Otherwise, please delete the template.

I Want to Do

I want to leave func in the request body empty and use @ filter to retrieve directly, Or, I want to know, is the performance of filter for or better than func for in.

What I Did

I tried to leave it blank, but I got an error

Dgraph Metadata

dgraph version

v20.11.0

I was confused for a sec, but after I got it, I’m still confused. You wanna filter without a Root query? In order to filter something, you have to define what is that something. And you do by querying it with the Root query. There’s no way to filter what is unknown.

There’s any reason you are doing like this? so I might help to guide you in another way.

OK, thank you, because I think the syntax of ‘func’ is similar to ‘@ filter’. I want to confirm whether it can be replaced, but if ‘func’ is a root search, it should not be possible.

Yeah, you need a Root query “(func: etc…)”.

I understand where you are at. “How do you do an OR” in DQL root function to get two nodes by id if the root function only accepts a single function

There are two primary ways to do this.

Wider Function Query with Filter to reduce

You have to have a root function, so if your root function is wide enough the include both of the smaller functions then you can do it all in a single query block:

{
  sourceNodes(func: has(identity_id)) @filter(eq(identity_id, "test_1_lyf00824") OR eq(identity_id, "269783243924963328")) {
    uid
    # other predicates/edges
  }
}

Pros: A single query block easy to create dynamically
Cons: Touches more nodes causing decreased efficiency

Var Blocks for Better Performance

Alternatively, you can only touch the two nodes that you need at the root level by using var blocks to get the uids of the specific nodes. The uid function accepts a list of ids or variables in a single function. This list acts as an any of logic, so this exact syntax would not work to get nodes that intersect between two variables.

{
  var var1(func: eq(identity_id, "test_1_lyf00824"))
  var var2(func: eq(identity_id, "269783243924963328"))
  sourceNodes(func: uid(var1, var2)) {
    uid
    namespace
    # other predicates/edges
  }
}

Pros: More efficient. Touches only the nodes expected.
Cons: Can be more complex to create dynamically. Only works with OR logic ATM. (See Intersect version of uid(…) )

Yes, thank you for your guidance.