There are currently some unidirectional IS_FRIENDS_WITH edges in our graph (where a IS_FRIENDS_WITH b and not vice versa). I want to write a query that will for every such uni-directional edge from a->b, draw a matching edge b IS_FRIENDS_WITH a. At the end of this operation, the intention is that we will know that every IS_FRIENDS_WITH edge has a corresponding incoming edge.
I tried this:
let uniDirectionalEdges = await g
.V()
.hasLabel('user')
.as('outgoingUser')
.out('IS_FRIENDS_WITH')
// NOTE: failing here. Attempts to see if the edge already has a corresponding incoming edge.
.where(__.not(__.out('IS_FRIENDS_WITH').hasId(__.select('outgoingUser').id())))
// if there is no such edge, add it. I believe this part will work fine.
.addE('IS_FRIENDS_WITH')
.to(__.select('outgoingUser'))
.toList();
It fails with the message: Expected an id that is convertible to String but received class org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.DefaultGraphTraversal.
It appears that I’m failing to compare a vertex later in the traversal to the outgoingUser vertex because of a type issue. I also tried is, which doesn’t work and is meant for constant values. What is the right way to compare a vertex to an earlier vertex in the traversal and check for equality? I’m also open to different approaches. I’m just looking to get the job done.