Node.js 蔚蓝宇宙+;gremlinnodejs,如何以脚本形式提交流畅的查询(不是字节码——我知道它还不受支持)

Node.js 蔚蓝宇宙+;gremlinnodejs,如何以脚本形式提交流畅的查询(不是字节码——我知道它还不受支持),node.js,azure,gremlin,azure-cosmosdb-gremlinapi,Node.js,Azure,Gremlin,Azure Cosmosdb Gremlinapi,我正在尝试用nodejs为cosmosdb编写流畅的gremlin查询,即使它们是以字符串形式提交的。我已经阅读了文档,并且在一些github线程中看到它,虽然字节码还不受支持,但是可以以scrip的形式提交 到目前为止,我掌握的代码是: 配置客户端功能: export const CosmosConn = async (): Promise<driver.Client> => { try { const cosmosKey: string = awa

我正在尝试用nodejs为cosmosdb编写流畅的gremlin查询,即使它们是以字符串形式提交的。我已经阅读了文档,并且在一些github线程中看到它,虽然字节码还不受支持,但是可以以scrip的形式提交

到目前为止,我掌握的代码是:

配置客户端功能:


export const CosmosConn = async (): Promise<driver.Client> => {
    try {
        const cosmosKey: string = await GetSecret('cosmos-key');
        const cosmosEndpoint: string = await GetSecret('cosmos-endpoint');

        const authenticator: driver.auth.PlainTextSaslAuthenticator = new gremlin.driver.auth.PlainTextSaslAuthenticator(
            '/dbs/main/colls/main',
            cosmosKey
        );
        const client: driver.Client = new gremlin.driver.Client(cosmosEndpoint, {
            authenticator,
            traversalsource: 'g',
            rejectUnauthorized: true,
            mimeType: 'application/vnd.gremlin-v2.0+json'
        });

        return client;
    } catch (err) {
        console.error(err);
    }
};
这当然会抛出一个错误:

Gremlin Query Syntax Error: Script compile error: Unexpected token: 'Object'; in input: '[objectObject'. @ line 1, column 9.


在提交之前,您是否尝试打印
翻译程序。翻译(查询)

根据我的经验,翻译人员对非平凡查询的支持非常有限


据微软称,他们计划在12月19日支持fluent API,所以最好等待官方的支持

正是这些类型阻止我以一种与CosmosDB兼容的方式初始化我的翻译程序

    const translator = new gremlin.process.Translator('g' as any);

工作原理。

下面是一个使用TypeScript中的Translator将CosmosDB的字节码查询转换为字符串查询的示例。我不推荐这个解决方案,就像另一个回答指出的那样:它是有限的。改用AWS Neptune或等到MS在CosmosDB中实现字节码查询

async function test(): Promise<void> {
   // Connection:
   const traversal = Gremlin.process.AnonymousTraversalSource.traversal;
   const DriverRemoteConnection = Gremlin.driver.DriverRemoteConnection;
   const g = traversal().withRemote(new DriverRemoteConnection("ws://localhost:8182/gremlin"));

   // Create translator
   const translator = new Gremlin.process.Translator(g);

   // Convert bytecode query to string query for CosmosDB:
   console.log(translator.translate(g.V().hasLabel('person').values('name').getBytecode()))
}

test();
异步函数测试():Promise{
//连接:
const traversal=Gremlin.process.AnonymousTraversalSource.traversal;
const DriverRemoteConnection=Gremlin.driver.DriverRemoteConnection;
const g=traversal().withRemote(新的DriverRemoteConnection(“ws://localhost:8182/gremlin”);
//创建翻译器
const translator=new Gremlin.process.translator(g);
//将CosmosDB的字节码查询转换为字符串查询:
console.log(translator.translate(g.V().hasLabel('person')).values('name').getBytecode())
}
test();

这里是测试用例的链接,以使getbytecode翻译工作正常

编辑:-

下面是来自上面链接的示例测试用例

it('should produce valid script representation from bytecode glv steps', function () {
      const g = new graph.Graph().traversal();
      const script = new Translator('g').translate(g.V().out('created').getBytecode());
      assert.ok(script);
      assert.strictEqual(script, 'g.V().out(\'created\')');
});

我很高兴再等几周,只是fluent API承诺在2018年上半年推出,所以不确定该截止日期的可信度。实际上,在你发布这篇文章的第二天,他们已经将这篇文章的时间线更新到2020年上半年,所以,如果我们幸运的话,可能是2020年7月?真是太遗憾了。幸好他们有竞争对手(Amazon Neptune?)啊,我不想为了这个原因将我们所有的基础设施移出Azure:(然而,有些事情越来越让人沮丧……您好,从2020年9月开始:-/虽然此链接可能会回答问题,但最好在此处包含答案的基本部分,并提供链接供参考。如果链接页面发生更改,则仅链接的答案可能无效。-使用示例测试用例编辑答案
async function test(): Promise<void> {
   // Connection:
   const traversal = Gremlin.process.AnonymousTraversalSource.traversal;
   const DriverRemoteConnection = Gremlin.driver.DriverRemoteConnection;
   const g = traversal().withRemote(new DriverRemoteConnection("ws://localhost:8182/gremlin"));

   // Create translator
   const translator = new Gremlin.process.Translator(g);

   // Convert bytecode query to string query for CosmosDB:
   console.log(translator.translate(g.V().hasLabel('person').values('name').getBytecode()))
}

test();
it('should produce valid script representation from bytecode glv steps', function () {
      const g = new graph.Graph().traversal();
      const script = new Translator('g').translate(g.V().out('created').getBytecode());
      assert.ok(script);
      assert.strictEqual(script, 'g.V().out(\'created\')');
});