0
votes

I am trying to add edge to an existing node in gremlin-python. But graph traversal(g) object do not have addE method and vertex do not have addEdge method.

1
I know there are ways to do it like mentioned in this answer: stackoverflow.com/questions/40657636/… but I want to do it like g.addE().from_(a).to(b).toList() - Bipul Karnani

1 Answers

2
votes

You can do it with a mid-traversal V():

>>> vFrom = g.V(1).next()
>>> vTo = g.V(6).next()
>>> g.V(vTo).as_('t').V(vFrom).addE("knows").to("t").toList()
[e[13][1-knows->6]]

I did learn that there is a bug that prevents this approach that uses withSideEffect() in TinkerPop 3.2.4:

>>> g.withSideEffect("t",vTo).V(vFrom).addE("knows").to("t").toList()

I created an issue to help track the bug.