title: Azure Cosmos Graph nest edge vertex in a vertex property
body: <p>I have two vertex:</p>
  
  <p>1) Vertex 1: <code>{ id: 1, name: “john” }</code></p>
  
  <p>2) Vertex 2: <code>{ id: 2, name: “mary” }</code></p>
  
  <p>There is an edge from 1 to 2 named “children”.</p>
  
  <p>Is it possible to return 2 nested in 1 using gremlin like this?</p>
  
  <pre><code>  { 
      id: 1, 
      name: “john”,
      children: { id: 2, name: “mary” }
    }
  </code></pre>
  
  <p>Thank you!</p>
  
  <p>My solution with an amazing help of @noam621 ---------------------------------</p>
  
  <pre><code>
  g.V(1)
  .union( valueMap(true),
          project('children').by( coalesce( out('children').valueMap(true).fold() , constant([]))),
          project('parents').by( coalesce( out('parents').valueMap(true).fold() , constant([])))
  )
  .unfold().group().by(keys).by(select(values))
  
  </code></pre>
  
  <p>It returns the following object:</p>
  
  <pre><code>{ 
      id: 1, 
      name: [ “john” ],
      children: [ { id: 2, name: [ “mary” ] } ],
      parents: []
  }
  </code></pre>
  
  <p>.union with project are the key to merge all objects in one object.
  valueMap(true).fold() is fundamental to get all objects in the edge and coalesce helps with a default value if the edge doesn't return any vertex.</p>
  
  <p>Due to some Azure Cosmos gremlin limitations is only possible to get values as array values.
  Thus I finalized the object formatting in my application code. It's ok for now.</p>
  
  <p>Thank you!</p>