Path existence (NOT shortest path)

Finding the shortest path between any two Dgraph nodes is useful, but in certain contexts, knowing that there is any path at all is still very useful.

For example, if we are storing some hierarchical system in Dgraph, knowing whether two nodes are connected by some predicate(s) might tell us whether they are semantically related.

I imagine something relatively simple like depth-first search would be perfectly sufficient for implementing this, and would presumably have the additional benefit of being much faster than a shortest-path query, but then again I’m not sure how difficult this would be to add to Dgraph’s codebase.

1 Like

Maybe this query would help you on that https://docs.dgraph.io/query-language/#recurse-query

You can also do like:


{
	test(func: has(myPredicate), first: 10) @recurse(depth: 50, loop: true) {
		uid
        expand(_all_){ expand(_all_) }
	}
}

or


{
	test(func: qe(myPredicate, "some indexed node with exact")) @recurse(depth: 50, loop: true) {
		uid
        expand(_all_){ expand(_all_) }
	}
}
1 Like