I’m working with a Dgraph dataset where nodes have different types and are connected by a RELATED_TO
edge with facets.
Here’s a simplified version of the dataset:
_:node_11 <dgraph.type> "Node_Type1" .
_:node_11 <name> "abc1" .
_:node_12 <dgraph.type> "Node_Type1" .
_:node_12 <name> "abc2" .
_:node_13 <dgraph.type> "Node_Type1" .
_:node_13 <name> "abc3" .
_:node_21 <dgraph.type> "Node_Type2" .
_:node_21 <name> "xyz1" .
_:node_22 <dgraph.type> "Node_Type2" .
_:node_22 <name> "xyz2" .
_:node_23 <dgraph.type> "Node_Type2" .
_:node_23 <name> "xyz3" .
_:node_31 <dgraph.type> "Node_Type3" .
_:node_31 <name> "asdf1" .
_:node_32 <dgraph.type> "Node_Type3" .
_:node_32 <name> "asdf2" .
_:node_33 <dgraph.type> "Node_Type3" .
_:node_33 <name> "asdf3" .
# Relationships
_:node_11 <RELATED_TO> _:node_21 (rel_type="CONNECTED") .
_:node_21 <RELATED_TO> _:node_31 (rel_type="CONNECTED") .
_:node_12 <RELATED_TO> _:node_23 (rel_type="CONNECTED") .
_:node_23 <RELATED_TO> _:node_42 (rel_type="CONNECTED") .
_:node_11 <RELATED_TO> _:node_43 (rel_type="CONNECTED") .
_:node_43 <RELATED_TO> _:node_31 (rel_type="CONNECTED") .
_:node_13 <RELATED_TO> _:node_23 (rel_type="CONNECTED") .
_:node_23 <RELATED_TO> _:node_43 (rel_type="CONNECTED") .
What I want to achieve:
-
Fetch all paths between nodes of type
Node_Type1
andNode_Type2
-
Limit search to depth = 2
-
Include all possible paths, not just the shortest one
Example Expected Output:
From the above dataset, I would expect something like:
-
node_11 -> node_21 -> node_31
-
node_11 -> node_43 -> node_31
What I tried:
I tried using the shortest
query in Dgraph:
{
path as shortest(from: 0x146f52e7, to: 0x14801bbe, depth: 2) {
RELATED_TO
}
path(func: uid(path)) {
uid
expand(_all_)
}
}
But this only gives me the shortest path between two nodes, not all possible paths of a given depth.
Question:
How can I query Dgraph to get all paths between two node types (Node_Type1
→ Node_Type2
) with a depth of 2, instead of just the shortest path?