 # Return a subgraph using a query

#1

Dear community,

I have the following example dataset:

``````{
set{
_:nodeA <name> "node a" .
_:nodeB <name> "node b" .
_:nodeC <name> "node c" .
_:nodeD <name> "node d" .
_:nodeE <name> "node e" .
_:nodeF <name> "node f" .
_:nodeG <name> "node g" .
_:nodeA <relation> _:nodeG .
_:nodeA <relation> _nodeD .
_:nodeB <relation> _nodeA .
_:nodeC <relation> _nodeB .
_:nodeC <relation> _nodeF .
_:nodeD <relation> _nodeG .
_:nodeD <relation> _nodeC .
_:nodeE <relation> _nodeA .
_:nodeE <relation> _nodeC .

}
}
``````

and I have defined reverse edges for “relation”.
Here you can find an image of the nodes and edges from ratel:

I would like to find any direct or indirect connection from the nodes d and e to the nodes a, b and c. Thus the result of the query should return the nodes a, b, c, d, e and g including the edges and reverse edges between them (but not the node f).

I thought that I could use the recurse function, like:

``````{
subgraph(func: has(name))@filter(eq(name, "node d") OR eq(name, "node e"))@recurse{
name@filter(eq(name, "node a") OR eq(name, "node b") OR eq(name, "node c"))
relation
~relation

}
}
``````

but this returns the whole graph.

Can you help me? Thanks a lot!