title: Gremlin / tinkerpop: insert key:value property constant in every vertex and edge traversed then return path
body: <p>Using AWS Neptune with Gremlin query language (last version).</p>
  <p>Using sample data inserted this way:</p>
  <pre><code>g.addV('test_report').property('name', 'REF').property('creationDateTime','2022-07-01 00:00:00.000000')
  g.addV('test_reportrelease').property('name', 'A').property('creationDateTime','2022-07-01 01:00:00.000000')
  g.addV('test_reportrelease').property('name', 'B').property('creationDateTime','2022-07-01 02:00:00.000000')
  g.addV('test_reportrelease').property('name', 'C').property('creationDateTime','2022-07-01 03:00:00.000000')
  
  g.addE('test_has').property('creationDateTime','2022-07-02 01:00:00.000000')
  .from(V().hasLabel('test_report').has('name', 'REF'))
  .to(V().hasLabel('test_reportrelease').has('name', 'A'))
  
  g.addE('test_has').property('creationDateTime','2022-07-02 02:00:00.000000')
  .from(V().hasLabel('test_report').has('name', 'REF'))
  .to(V().hasLabel('test_reportrelease').has('name', 'B'))
  
  g.addE('test_has').property('creationDateTime','2022-07-02 03:00:00.000000')
  .from(V().hasLabel('test_report').has('name', 'REF'))
  .to(V().hasLabel('test_reportrelease').has('name', 'C'))
  </code></pre>
  <p>What I want is:</p>
  <ul>
  <li>First of all, get the vertices with label &quot;test_report&quot;</li>
  <li>then follow all the next statements (union)</li>
  <li>then follow, if exists, all outgoing edges (outE) with the label &quot;test_has&quot; between vertices with label &quot;test_report&quot; and &quot;test_reportrelease&quot;; then follow all ingoing vertices (inV), and apply a constant with name &quot;ref&quot; and value test_has&quot; on every edge browsed</li>
  <li>then follow, if exists, as well the edge &quot;test_has&quot; and ingoing vertices but keep only the first result according to an asc order on creationDateTime, and apply a constant  with name &quot;ref&quot; and value &quot;test_first&quot; on every edge browsed</li>
  <li>then follow, if exists, as well the edge &quot;test_has&quot; but and ingoing vertices keep only the first result according to a desc order on creationDateTime, and apply a constant  with name &quot;ref&quot; and value &quot;test_last&quot; on every edge browsed</li>
  <li>then use the tree() step to get all browsed vertices and edges as a tree</li>
  </ul>
  <p>The main problem is to add the &quot;ref&quot; constant to every edge followed (or change the label at query time).</p>
  <p>The sample query I wrote for most of my needs, missing the &quot;ref&quot; constant, is:</p>
  <pre><code>g.V().hasLabel('test_report')
  .union(optional(
  outE().hasLabel('test_has').order().by('creationDateTime').inV()),
  optional(outE().hasLabel('test_has').order().by('creationDateTime').limit(1).inV()),
  optional(outE().hasLabel('test_has').order().by(coalesce(values('creationDateTime'), constant('')), desc).limit(1).store('last').inV())
  ).valueMap(true).path()
  </code></pre>
  <p><strong>Question: How to insert a key:value constant property on every edge or vertex traversed ?</strong></p>
  <p>So that the result looks like this (but formatted as a tree - path being more readable when testing):</p>
  <pre><code>1   path[v[70c0dcd5-a6b9-4532-28bf-85705e94697e], e[66c0dcd7-31ed-e381-5331-e8c73bb91be1][70c0dcd5-a6b9-4532-28bf-85705e94697e-test_has-&gt;c0c0dcd5-c102-4031-d739-b5bd8fe161bc], v[c0c0dcd5-c102-4031-d739-b5bd8fe161bc], {&lt;T.id: 1&gt;: 'c0c0dcd5-c102-4031-d739-b5bd8fe161bc', &lt;T.label: 4&gt;: 'test_reportrelease', 'name': ['A'], 'creationDateTime': ['2022-07-01 01:00:00.000000'], 'ref': ['test_has']}]
  2   path[v[70c0dcd5-a6b9-4532-28bf-85705e94697e], e[b0c0dcd7-4d99-1f3c-077d-decd2e251c46][70c0dcd5-a6b9-4532-28bf-85705e94697e-test_has-&gt;68c0dcd5-c5c5-c869-d789-96acbb88131f], v[68c0dcd5-c5c5-c869-d789-96acbb88131f], {&lt;T.id: 1&gt;: '68c0dcd5-c5c5-c869-d789-96acbb88131f', &lt;T.label: 4&gt;: 'test_reportrelease', 'name': ['B'], 'creationDateTime': ['2022-07-01 02:00:00.000000'], 'ref': ['test_has']}]
  3   path[v[70c0dcd5-a6b9-4532-28bf-85705e94697e], e[70c0dcd7-72ac-204f-1341-cc843d165a38][70c0dcd5-a6b9-4532-28bf-85705e94697e-test_has-&gt;5ac0dcd5-cb10-f392-7d80-69541c4f22eb], v[5ac0dcd5-cb10-f392-7d80-69541c4f22eb], {&lt;T.id: 1&gt;: '5ac0dcd5-cb10-f392-7d80-69541c4f22eb', &lt;T.label: 4&gt;: 'test_reportrelease', 'name': ['C'], 'creationDateTime': ['2022-07-01 03:00:00.000000'], 'ref': ['test_has']}]
  4   path[v[70c0dcd5-a6b9-4532-28bf-85705e94697e], e[66c0dcd7-31ed-e381-5331-e8c73bb91be1][70c0dcd5-a6b9-4532-28bf-85705e94697e-test_has-&gt;c0c0dcd5-c102-4031-d739-b5bd8fe161bc], v[c0c0dcd5-c102-4031-d739-b5bd8fe161bc], {&lt;T.id: 1&gt;: 'c0c0dcd5-c102-4031-d739-b5bd8fe161bc', &lt;T.label: 4&gt;: 'test_reportrelease', 'name': ['A'], 'creationDateTime': ['2022-07-01 01:00:00.000000'], 'ref': ['test_first']}]
  5   path[v[70c0dcd5-a6b9-4532-28bf-85705e94697e], e[70c0dcd7-72ac-204f-1341-cc843d165a38][70c0dcd5-a6b9-4532-28bf-85705e94697e-test_has-&gt;5ac0dcd5-cb10-f392-7d80-69541c4f22eb], v[5ac0dcd5-cb10-f392-7d80-69541c4f22eb], {&lt;T.id: 1&gt;: '5ac0dcd5-cb10-f392-7d80-69541c4f22eb', &lt;T.label: 4&gt;: 'test_reportrelease', 'name': ['C'], 'creationDateTime': ['2022-07-01 03:00:00.000000'], 'ref': ['test_last']}]
  
  </code></pre>
  <p>I have tried those approaches, but both interrupt the graph traversal when using valueMap:</p>
  <pre><code>g.V().hasLabel('test_report').outE().hasLabel('test_has')
  .order().by('creationDateTime').limit(1).valueMap(true).unfold().inject(['ref':'test_first']).fold()
  </code></pre>
  <p>And</p>
  <pre><code>g.V().hasLabel('test_report').outE().hasLabel('test_has')
  .order().by('creationDateTime').limit(1).union(valueMap(true).unfold(), project('ref').by(constant('test_first'))).fold()
  </code></pre>
  <p>Is there a way to achieve such thing ?</p>
  <p>I don't want to have the results stored in the database, just need to have the values in the results.</p>
  <p>PS: I'm querying my graph db from a Jupyter SageMaker Notebook.</p>