g.V().has('name', 'alice').both().both().cyclicPath().path().by('name')
Why we need 2 both()s to get the cyclicPath()?
It's not completely clear as to what you are asking but your traversal is simply translating to:
g.V().has('name', 'alice'). // (1)
both(). // (2)
both(). // (3)
cyclicPath(). // (4)
path().by('name') // (5)
- Find the vertex with the "name" of "alice"
- Traverse away from "alice" on both incoming and outgoing edges to adjacent vertices
- For all of those vertices traverse away again on both incoming and outgoing edges to adjacent vertices. It is worth noting that some of those paths will go back to "alice"
- Examine the path that the traverser took in getting this far and filter out any paths that do not return to their start (i.e. do not return to "alice"). The alternative to this step is
simplePath()
which would filter out paths that cycle (i.e. go back to start).
- Display the paths followed and extract the "name" property into the path for each vertex in the path.