0

I am trying to execute a gremlin script over https against a remote JanusGraph instance. I have filtered my problem to the part where I am trying to add an edge using vertex variables. I am trying to add two vertices, assign the results to a variable and use them to add an edge. Also I am also tying to avoid a single line script like g.V().addV(..).aaddV(..).addE(..), because of the program logic that is behind the script

The following gremlin works in the gremlin console (remote session)

def graph=ConfiguredGraphFactory.open("ga"); 
def g = graph.traversal(); 
v1=g.addV('node1');
v2=g.addV('node2');
v1.addE('test').to(v2);

But when I try to do the same over https (issued against a compose-janusgraph server), I get an error. I did add .iterate() to the addV() and the vertexes are getting added if I remove the addE(..) line. But when I try

{"gremlin":"def graph=ConfiguredGraphFactory.open('ga'); 
def g = graph.traversal();
v1=g.addV('node16').property('name','testn16').iterate();
v2=g.addV('node17').property('name','testn2').iterate();
v1.addE('test18').to(v2);
g.tx().commit()"}

I get the exception

The traversal strategies are complete and the traversal can no longer be modulated","Exception-Class":"java.lang.IllegalStateException"

Also note that I am joining the whole gremlin into one single line before sending it over curl. I have split them to newlines here for readability. Any help would be great. -- Thank you

Max Arbiter
  • 318
  • 4
  • 18

1 Answers1

2

iterate() doesn't return a Vertex...it just iterates the traversal to generate side-effects (i.e. the graph gets a vertex added but no result is returned). You probably just need to do:

{"gremlin":"graph=ConfiguredGraphFactory.open('ga'); 
g = graph.traversal();
g.addV('node16').property('name','testn16').as('v1').
  addV('node17').property('name','testn2').as('v2').
  addE('test18').from('v1').to('v2').iterate();
g.tx().commit()"}
stephen mallette
  • 45,298
  • 5
  • 67
  • 135
  • Thanks a lot, Stephen. I misunderstood the meaning of iterate. I thought it returns a vertex, so I did not realize I could do `.addE().from().to()` – Max Arbiter Feb 26 '19 at 17:15
  • you could sorta do it the way you were doing it to, but instead of `iterate()` you would have done `next()`, but it's generally nicer to do it as a single traversal. – stephen mallette Feb 26 '19 at 17:22