I am trying to get the hops that are needed to reach from node a to node b in a recursive fashion
I know that this is possible to achieve using the shortest path function, but what would be even better is to get the current depth inside a recurse function.
{
tree(func: eq(name, leaf)) @recurse {
name as uid
~next {}
#current_depth
}
findtree(func: uid(name)) @filter(eq(dgraph.type, Tree)) {
name
}
}
By this way I will be getting the depth at which the Tree is found as well. This tree in this case is root node, but it can be some intermediate node as well based on filters.
Is there a better way of getting the depth or steps from the leaf to the tree in this case.
Just let me know if this even possible? Is there an alternate way to do the same ? I tried writing a function for shortest path, but it accepts only single uids, not lists, what if I want to get the shortest distance between multiple node pairs
Distance between [a,b,c] * [x,y,z]. Distance or shortest path between the cross product of the lists
By current depth I meant the total number of hops (distance) needed to reach a particular parent node.
Which is basically the depth value in the recurse query. Internally depth value will be used in the recursive function. Just wanted to know of that value is available as a variable in Graphql
I am not an expert on Cypher. But are you sure this is a recurse query?
It seems to me to be a query that says “Match any Tree entity that has any edge for Code entity”. This does not seem to me to be a recursive query itself in the sense of traverse. I don’t know how Cypher does recurse query tho.
Consider this query below:
{
var(func: uid(T)){
g as count(uid)
}
stats(){
F as TotalTraversed : sum(val(g))
Hops: math(F-1)
}
q(func: eq(name, "Root")) @recurse {
T as uid
name
next
}
}