为什么这个图遍历对象没有.from()函数? Nodejs 中的 gremlin 查询

问题描述 投票:0回答:1

我遇到了一个错误,这是它在nodejs中的最小复制。

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

这让我感到非常惊讶,因为在我看来,我遵循的是这里这里这样的例子。我看不出有什么区别。

但这就是它给我的错误。

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

以防万一此错误与连接的设置方式有关(我对此表示怀疑),并且为了让应答者更容易复制,这里是整个文件(删除了一些敏感值)。

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();
gremlin tinkerpop amazon-neptune
1个回答
0
投票

from()
需要是
from_()
https://tinkerpop.apache.org/docs/current/reference/#gremlin-javascript-differences

否则,JS 与 Gremlin 中的保留语法会存在一些冲突。

最新问题
© www.soinside.com 2019 - 2025. All rights reserved.