gremlintinkerpopamazon-neptune

why doesn't this graph traversal object have a .from() function? gremlin query in nodejs


I've encountered a bug, and here is the minimal replication of it in nodejs.

g.addV("foo").as("x").addV("bar").as("y").addE("relatesTo").from("x").to("y").next();

This is very surprising to me, because it seems to me to follow examples like those here and here. I can't tell the difference.

But here's the error it's giving me.

await this.g.addV("foo").as("x").addV("bar").as("y").addE("relatesTo").from("x").to("y").next();
                                                                       ^

TypeError: this.g.addV(...).as(...).addV(...).as(...).addE(...).from is not a function

Just in case this error was related to the way the connection was set up (which I doubt), and to make it easier for answerers to replicate, here's the entire file (with a few sensitive values removed).

let { fromNodeProviderChain } = require( '@aws-sdk/credential-providers');
let aws4 = require( 'aws4');
let gremlin = require ('gremlin');

class dbManager {
  constructor() {
    this.initNeptuneConnection();
  }

  initNeptuneConnection = async () => {
    const credGetter = fromNodeProviderChain();
    const creds = await credGetter();
    const url = '< your url here >';
    const { host, pathname } = new URL(url);
    const { headers } = await aws4.sign(
      {
        host,
        path: pathname,
        region: 'some region here',
        service: 'neptune-db',
      },
      creds
    );
    const connection = new gremlin.driver.DriverRemoteConnection(url, { headers });
    await connection.open();
    this.g = new gremlin.structure.Graph().traversal().withRemote(connection);
    this.__ = gremlin.process.statics;
    await this.g.addV("foo").as("x").addV("bar").as("y").addE("relatesTo").from("x").to("y").next();
  };
}
let db = new dbManager();

Solution

  • from() needs to be from_(): https://tinkerpop.apache.org/docs/current/reference/#gremlin-javascript-differences

    Otherwise, there are some collisions in reserved syntax in JS vs Gremlin.