3

我创建了一个 AWS AppSync graphql api,它在被调用时将运行一个 AWS Lambda 函数,该函数将使用查询语言 Gremlin 创建一个顶点和边,但是在成功创建顶点后我无法创建边,并且 AWS AppSync 给了我这个错误 “消息”:“g.addE(...).from 不是函数”

这是我的 lambda 函数代码,如果我的代码有问题,请检查一下?告诉我我的错误在哪里?

import { process as gprocess } from 'gremlin';
import Post from './Post'
const gremlin = require('gremlin')
const DriverRemoteConnection = gremlin.driver.DriverRemoteConnection
const Graph = gremlin.structure.Graph
const uri = process.env.WRITER
const { t, P, } = gprocess;
const __ = gprocess.statics;

async function createPost(post: Post) {

    let dc = new DriverRemoteConnection(`wss://${uri}/gremlin`, {})

    const graph = new Graph()
    const g = graph.traversal().withRemote(dc)  

    let vertex = await g.addV('posts').property('title',post.title).property('content', post.content).property('id', post.id).next()

    let edge = await g.addE('post_to_post').from(g.V().hasLabel('posts').next()).to(g.V().hasLabel('posts').next()).next()

    dc.close()

    return post;
}

export default createPost
4

1 回答 1

1

在 Javascriptfrom中是一个保留字。当 Gremlin 有这样的冲突时,Javascript 中步骤命名的约定是在步骤的后缀上附加一个下划线。因此,您将其称为from_(). 您可以在此处的文档中看到这一点,并注意对于from() 此处表示其他步骤,Javascript 中还有其他类似的差异。

于 2021-09-28T11:13:09.387 回答