我已经创建了一个 AWS AppSync graphql api,它在被调用时将运行一个 AWS Lambda 函数,该函数将使用查询语言 Gremlin 创建一个顶点和边,但是在成功创建顶点并且 AWS AppSync 给我后我无法创建边此错误 "message": "g.addE(...).from is not a function"
这是我的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
最佳答案
在 Javascript 中,from
是一个保留字。当 Gremlin 有此类冲突时,Javascript 中步骤命名的约定是在步骤的后缀后添加下划线。因此,您可以将其称为 from_()
。您可以在 from()
here 的文档中看到这一点并注意在 Javascript 中对于表示为 here 的其他步骤还有其他类似的差异.
关于typescript - 无法创建边缘,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69355469/