I am using Cosmos DB - Graph to store data and developing API to query graph db and return query results in below format. API can accept any node type and id as parameter and traverse through in & out edges to return nested vertex and edges.

```
{
    "nodes":[
        {"id":"1","name":"A"},
        {"id":"2","name":"B"},
        {"id":"3","name":"C1"},
        {"id":"4","name":"C2"},
        {"id":"5","name":"C3"},
        {"id":"6","name":"D1"},
        {"id":"7","name":"D2"},
        {"id":"8","name":"D3"}
    ],
    "edges":[
        {"source":"1","target":"2"},
        {"source":"2","target":"3"},
        {"source":"2","target":"4"},
        {"source":"2","target":"5"},
        {"source":"3","target":"6"},
        {"source":"4","target":"7"},
        {"source":"5","target":"8"}
    ]
}

```

Sample Graph: 

[![Sample Graph](https://i.stack.imgur.com/RMdJ0.png)](https://i.stack.imgur.com/RMdJ0.png) 

I am new to gremlin graph query and facing issue to traverse through graph. I got few samples to get in & out edges and looking for vertex query. I am planning to execute 4 queries to generate the above format:

**For Edges** 

```
g.V().has('name', 'A').repeat(__.bothE().where(without('e')).store('e').otherV()).cap('e')
g.V().has('name', 'A').repeat(__.inE().where(without('e')).store('e').outV()).cap('e')

```

**For Nodes**

```
g.V().has('name', 'A').repeat(out()).until(outE().count().is(0)).simplePath()

```

I tried couple of sample query but not able to get all in & out vertex. I am looking for query that returns all vertex or any better solution to reduce the query to build the output in JSON format.