I'm using Gremlin with AWS Neptune, and trying to add 2 vertices and 1 edge atomically. I've essentially used fold() + coalesce()
semantics to traverse along the way such that I keep creating the elements if not already present. This is what I've come up with and was wondering if people have better alternatives to it.
g.V("America")
.fold()
.coalesce(unfold(), addV("Country")
.property(T.id, "America")
.property("Population", 300_000_000))
.V("India")
.fold()
.coalesce(unfold(), addV("Country")
.property(T.id, "India")
.property("Population", 1_000_000_000))
.V("America")
.outE("connected")
.inV()
.has(T.id, "India")
.fold()
.coalesce(unfold(), addE("connected")
.property("distanceMiles", 8000)
.from(V("America"))
.to(V("India"))).next();
Also, are there any tips to make queries more readable? I'm using JAVA, and since the steps need to be chained, parts of the query cannot be extracted out to it's own method so that it's re-usable. Is this understanding correct?
And a final question: IntelliJ gives me warnings about the query in the form of Unchecked generics array creation for varargs parameter
which I am not being able to understand in this context. Can someone help clarify?
Thanks!