title: Cosmos DB: Graph - query all nested vertex & edges
body: <p>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 &amp; out edges to return nested vertex and edges.</p>
  
  <pre><code>{
      "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"}
      ]
  }
  </code></pre>
  
  <p>Sample Graph: </p>
  
  <p><a href="https://i.stack.imgur.com/RMdJ0.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/RMdJ0.png" alt="Sample Graph"></a> </p>
  
  <p>I am new to gremlin graph query and facing issue to traverse through graph. I got few samples to get in &amp; out edges and looking for vertex query. I am planning to execute 4 queries to generate the above format:</p>
  
  <p><strong>For Edges</strong> </p>
  
  <pre><code>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')
  </code></pre>
  
  <p><strong>For Nodes</strong></p>
  
  <pre><code>g.V().has('name', 'A').repeat(out()).until(outE().count().is(0)).simplePath()
  </code></pre>
  
  <p>I tried couple of sample query but not able to get all in &amp; 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. </p>