How can I insert a vertex between two currently connected vertexes?
<p>I am trying to to grips with Gremlin.  Having thoroughly read the documentation I still appear to be struggling with it conceptually.  </p>

<p>I am creating a basic newsfeed, following the model found in the Neo4j documentation here:</p>

<p><a href="http://neo4j.com/docs/snapshot/cypher-cookbook-newsfeed.html" rel="nofollow">http://neo4j.com/docs/snapshot/cypher-cookbook-newsfeed.html</a></p>

<p>I am actually using titandb, but am following the same sort of principles/schema as shown above.</p>

<p>So far I have created a graph of <code>user</code> vertexes, which are connected via <code>friend</code> edges.</p>

<p>And I am able to add a new <code>post</code> vertex and connect it via a <code>posted</code> edge to a <code>user</code> vertex like so:</p>

<pre><code> def activity = graph.addVertex(T.label, "post");
 activity.property("post_id", post_id);
 activity.property("time", time);
 activity.property("body", body);

 def g = graph.traversal();
 def user = g.V().hasLabel("user").has("userid", userid).next();
 user.addEdge("posted", activity, "time", time);
</code></pre>

<p>However, I need to be able to do the following in a single Gremlin script:</p>

<ol>
<li>Create the new <code>post</code> vertex, as above.</li>
<li>Remove the old <code>posted</code> edge between the <code>user</code> and any currently connected <code>post</code> vertex. But <strong>only if</strong>, a post currently exists.</li>
<li>Attach the new <code>post</code> vertex to the <code>user</code> with a new <code>posted</code> edge.</li>
<li>Then finally, if there was a previous <code>post</code> vertex, attach it to the newly added <code>post</code> vertex via a <code>next</code> edge.  Ultimately creating long streams of posts for each user.</li>
</ol>

<p>I've been playing around, using trial and error, for what seems like hours now, and just cannot seem to get my head around it.</p>

<p>Any help would be greatly appreciated.</p>