gremlin .mergeE / .mergeV in javascript/typescript example

0

all examples for mergeV/mergeE seem to be groovy but it's not obvious how to translate them to javascript. I got as far as this:

const { onCreate, onMatch } = gremlin.process.merge;
const { from_, to } = gremlin.process.direction;

this
  .mergeE(to, tgt.id)
  .option(onCreate, { created: now, updated: now })
  .option(onMatch, { updated: now })

but the mergeE instruction generates an error.

I tried:

  1. .mergeE([to, tgt.id]) with the effect: "Could not locate exact method given the supplied arguments: NeptuneGraphTraversal.mergeE(ArrayList)"
  2. .mergeE(to, tgt.id) Could not locate exact method given the supplied arguments
  3. .mergeE({ [to.toString()]: tgt.id, [from_.toString()]: this.id }) an unexpected error has occured in Neptune; obviously we cannot do [to]: tgt.id in js

If anyone has a clear example for mergeE in javascript/typescript, it would help immensely. I'm asking specifically in the Amazon Neptune context but hopefully it can be useful for other cases as well. Even better would be to have a side-by side example for mergeV, but maybe a lot to ask.

Ideally the example will show how it's possible to merge from/to a node that was selected in a previous statement since this is a pattern especially when working in a dsl context.

Thank you

Note: this is an almost exact re:post of my question on stackoverflow. The only comment there so far is to try https://www.gremlator.com/, but it's probably helpful in other situations, not when looking for a full example. One thing i've learned from it though is that likely I should be using new Map(...) instead of a plain object where groovy maps are shown in the docs. Again, it would help to have this as a working example.

asked 9 months ago323 views
1 Answer
0

It looks like there was an answer on StackOverflow. Copying that example here to connect the dots.

const gremlin = require('gremlin');
const traversal = gremlin.process.AnonymousTraversalSource.traversal;
const DriverRemoteConnection = gremlin.driver.DriverRemoteConnection;
const direction = gremlin.process.direction
const t = gremlin.process.t
const { onCreate, onMatch } = gremlin.process.merge;

const g = traversal().withRemote(new DriverRemoteConnection('wss://<CLUSTER ENDPOINT>:8182/gremlin'));

g.
mergeE(new Map([[t.label,"Test"],
[direction.out,'1'],[direction.in,'2']])).
option(onCreate,new Map([["created",Date.now()]])).
option(onMatch,new Map([["updated",Date.now()]])).elementMap().toList().then(data => console.log(data))
AWS
AWS-KRL
answered 9 months ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions