I find the following code to create edge if it has not existed yet.
g.V().hasLabel("V1")
.has("userId", userId).as("a")
.V().hasLabel("V1").has("userId", userId2)
.coalesce(
bothE("link").where(outV().as("a")),
addE("link").from("a")
)
It works fine but I want to create both vertices and edge if they are not existed in 1 query.
I try the following code with new graph, it just create new vertices but no relation between them.
g.V().hasLabel("V1")
.has("userId", userId).fold()
.coalesce(
unfold(),
addV("V1").property("userId", userId1)
).as("a")
.V().hasLabel("V1").has("userId", userId2).fold()
.coalesce(
unfold(),
addV("V1").property("userId", userId2)
)
.coalesce(
bothE("link").where(outV().as("a")),
addE("link").from("a")
)