Ole Spaarmann
Ole Spaarmann

Reputation: 16761

Dgraph: Deep graph traversal possible with recurse?

I have a couple of questions regarding the capabilities of Dgraph regarding graph traversal.

Let's say we have a dataset that consists of nodes of the type post. Each post can have n posts that are replies to this post. The depth of this tree is not limited.

Is it possible with Dgraph to search trough all leaf nodes starting from one starting node and return all leafs that fulfill a certain condition?

Is it possible to set a depth limit to not end up with a gigantic dataset?

Is it also possible to find the children of all parent nodes that fulfill a certain condition?

And finally: Are edges in Dgraph directed? And can I include that in the query?

Upvotes: 2

Views: 1539

Answers (1)

Manish Jain
Manish Jain

Reputation: 241

Author of Dgraph here.

Is it possible with Dgraph to search trough all leaf nodes starting from one starting node and return all leafs that fulfill a certain condition?

Yes. You could use the recurse directive (https://docs.dgraph.io/query-language/#recurse-query).

Is it possible to set a depth limit to not end up with a gigantic dataset?

Yes. Recursion supports a maximum depth.

Is it also possible to find the children of all parent nodes that fulfill a certain condition?

Yes. You can traverse an edge, and put a filter on it. https://docs.dgraph.io/query-language/#applying-filters

And finally: Are edges in Dgraph directed? And can I include that in the query?

Edges in dgraph are directed. But, Dgraph also supports a "reverse" index, which can be used to automatically generate the edges in the reverse direction. You can then traverse these reverse edges, by adding a tilde (~) in front of the predicate name.

https://docs.dgraph.io/query-language/#reverse-edges

Upvotes: 7

Related Questions