0

I'm trying to use the technique described here for preventing duplicated edges in gremlin. I'm working in javascript and the query is failing with this error: Server error: Neither the map, sideEffects, nor path has a v-key: WhereEndStep(v) (500). This is the exact query I'm using:

import { process } from "gremlin";
const { statics } = process;
...
            g
            .V()
            .has('user', 'id', this.id)
            .fold()
            .coalesce(statics.unfold(), statics
                    .addV('user')
                    .property('id', this.id))
            .as('v')
            .V()
            .has('user', 'id', anotherUserId)
            .fold()
            .coalesce(statics.unfold(), statics
                    .addV('user')
                    .property('id', anotherUserId))
            .coalesce(statics
                    .inE('follow')
                    .where(
                        statics.outV().as('v')
                    ), statics.addE('follow').from_('v'))
            .V()
            .has('id', this.id)
            .outE('skip')
            .where(statics.inV().has('id', anotherUserId))
            .drop()
            .toList());

That's for completeness but the query never reaches the final outE('skip'), it fails at the last coalesce that's meant to prevent the duplicated edge. What could I be missing please?

Uche Ozoemena
  • 816
  • 2
  • 10
  • 25
  • Appears you are using the as() step and trying to reuse the defined labels after a reducing barrier step ( fold() in this case ). Labels do not persist across a fold(). You could try using aggregate() instead, just realize that aggregate creates a list that will need to be unfolded. – Taylor Riggan Apr 13 '22 at 15:13
  • Thanks @TaylorRiggan, what would the `aggregate` query look like please? I'm new to gremlin. – Uche Ozoemena Apr 13 '22 at 15:33

1 Answers1

1

As someone pointed out in the comments, the problem was that labels do not persist across a .fold(). My solution was to break up the queries so I could preserve the relevant label. What worked was this:

import { process } from "gremlin";
const { statics } = process;
...
            // first make sure the second user is available
            g = g
            .V()
            .has('user', 'id', anotherUserId)
            .fold()
            .coalesce(statics.unfold(), statics
                    .addV('user')
                    .property('id', anotherUserId))

            // then add the edge after making sure the first user is available
            g
            .V()
            .has('user', 'id', this.id)
            .fold()
            .coalesce(statics.unfold(), statics
                    .addV('user')
                    .property('id', this.id))
            .as('v')
            .V()
            .has('user', 'id', anotherUserId)
            .coalesce(statics
                    .inE('follow')
                    .where(
                        statics.outV().as('v')
                    ), statics.addE('follow').from_('v'))
            .V()
            .has('id', this.id)
            .outE('skip')
            .where(statics.inV().has('id', anotherUserId))
            .drop()
            .toList());
Uche Ozoemena
  • 816
  • 2
  • 10
  • 25