I am struggling with understanding how passing variables to child works. I am trying a query that (in my perception) is very similar to an example from A Tour of DGraph
In essence, I am trying to detect a loop of edges between four nodes: [dest_ip] -> [Flow] -> [src_ip] -> [DNS] -> [dest_IP]. When running the following query, I can see that there must exist one of those loops (see the matching uids of the destination IP address nodes):
{
loop(func: eq(dgraph.type, "Flow"), offset: 1, first: 1) { # Flow node
dest_ip { # destination IP node
uid
}
src_ip { # source IP node
uid
~requesting_ip { # edge to DNS node
uid
resolved_ip { # destination IP node again
uid
}
}
}
}
}
Thanks for the provided answer @MichelDiz. However, it doesn’t seem to work completely the way I’m expecting it to do. I adjusted your answer-query a bit to illustrate what is going on:
{
ORIGIN as var(func: eq(dgraph.type, "Flow"), offset: 0, first: 10) {
uid
dest_ip_node as dest_ip # destination IP node
}
loop(func: uid(ORIGIN)) @cascade { # Flow node
dest_ip {
uid
}
src_ip @cascade { # source IP node
uid
~requesting_ip @cascade { # edge to DNS node
uid
resolved_ip @filter(uid(dest_ip_node)) @cascade { # desination IP node again
uid
}
}
}
}
}
Adding some @cascade statement to filter out non-matching values. Most of the responses are what I expect:
As you can see, the uid of dest_ip equals the uid when traversing the src_ip -> ~requesting_ip -> resolved_ip edges, which is exactly the preferred answer. However, there are some answers in which is not the case:
In this answer, the IP uids do not match, but the uid of the resolved_ip matches another flow’s destination address (more specifically the uid fo the dest_ip node of the previous example response I wrote down above), which is what I am not looking for.
This should work as expected. Because in both blocks we are using the same UID, and dest_ip_node belongs to that node that we find in both blocks.
Maybe the problem is different, maybe dest_ip_node is capturing multiple UIDs. And don’t show others because of the cascade. Check if you can find multiple nodes. And if It had “0x535e1” before (can be a bug with delation).