Unable to create edges

Viewed 52

I have created an AWS AppSync graphql api which on being called will run an AWS Lambda function and that function will create a vertex and edge using query language Gremlin but I am unable create edge after vertex is successfully created and AWS AppSync giving me this error "message": "g.addE(...).from is not a function"

This is my lambda function code please check it if there is any problem in my code? tell me where is my mistake?

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
1 Answers

In Javascript from is a reserved word. When Gremlin has such conflicts the convention for step naming in Javascript is to append a underscore to the suffix of the step. Therefore you would refer to it as from_(). You can see that in the documentation for from() here and note that there are other similar differences in Javascript for other steps denoted here.

Related