Search code examples
graphgremlintinkerpop3amazon-neptune

Get a vertex with its label, properties and in/out vertices and their properties?


How can can find a vertex by name property and get:
1. vertices (with label and properties) incident on the incoming edges to this vertex?
2. vertices (with label and properties) incident on the outgoing edges to this vertex?
In a single query.

I am aware that .both() and .otherV() does this, and I can use .valueMap() and .label() to get the metadata and properties, but the result (response received from server) of .both() or .otherV() don't clearly indicate and identify what are the incoming vertices and what are the outgoing vertices.

To be able to distinguish between the two, I am calling:
* g.V().has('name', 'abcd').in().values('name') for indegrees
* g.V().has('name', 'abcd').out().values('name') for outdegrees
and
* g.V().has('name', 'abcd').union(label(),valueMap()) for metadata

to clearly know what response belongs to what set, specially in the indegrees and outdegrees case. But this is inefficient and results in 3 separate calls to the server.


Solution

  • In this case you should use project:

    g.V().has('name', 'josh').
      project('properties', 'out', 'in').
        by(valueMap().
            with(WithOptions.tokens)).
        by(out().values('name').fold()).
        by(__.in().values('name').fold())
    

    example: https://gremlify.com/c8nm1j16033g