0

I have created an AWS Appsync graphql api which on being called will run an aws lambda function and that function will query data from AWS Neptune using query language Gremlin but i am unable to retrieve data from aws neptune.

This is my lambda function

// import * as gremlin from "gremlin";
const gremlin = require("gremlin")

const DriverRemoteConnection = gremlin.driver.DriverRemoteConnection;
const Graph = gremlin.structure.Graph;
const uri = process.env.READER_ENDPOINT


const HighestRatedByCuisine = async () => {

    let dc = new DriverRemoteConnection(`wss://${uri}/gremlin`, {});
    const graph = new Graph();
    const g = graph.traversal().withRemote(dc)

    try {
        let data = await g.V().has("Person", "name", "Muhammad Ahsen Riaz").
            out("lives").in_("within").where(__.out("serves").
                has("name", P.within("Burgers"))).
            where(__.inE("about")).
            group().
            by(__.identity()).
            by(__.in_("about").values("rating")).
            order().
            by(values, Order.desc).
            unfold().
            order().by(values, Order.desc).limit(1).
            project("name", "address", "rating_average", "cuisine").
            by(__.select(Column.keys).values("name")).
            by(__.select(Column.keys).values("address")).
            by(__.select(Column.values)).
            by(__.select(Column.keys).out("serves").values("name")).next()

            console.log("Onlydata" , data)
            console.log("Data>>>" , data.value)
            console.log("data>>>>>" , data.done)
            console.log("JsonData" , JSON.stringify(data))


        return data.value
     
    }

    catch (err) {
        console.log("there is an error " , err)
        return err
    };

}

export default HighestRatedByCuisine


where as this is my schema

type HighestRatedRestaurantWithSpecificCuisine {
    name : String
    address : String
    cuisine : String
    rating_average : String
}

type Query {
 getHighestRatedRestaurantWithSpecificCuisine : HighestRatedRestaurantWithSpecificCuisine
}

Whenever a query throught appsync it returns null but when i console it in AWS CloudWatch it contains data in the form

    Data>>> Map {
  'name' => 'Burger Lab',
  'address' => '3648 Alek Forge',
  'rating_average' => '4',
  'cuisine' => 'Burgers' }


marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Ahsenriaz
  • 1
  • 1
  • I'm not sure if this is helpful but I have seen cases where as the Gremlin Javascript client returns a Map type that the Lambda is unable to return the result due to an issue when it tries to "stringify" the result. Are you seeing any errors in the Lambda function when it tries to return that result? If not do you have any mapping templates defined inside AppSync for the data that comes back from the Lambda? – Kelvin Lawrence Jun 10 '21 at 16:16
  • Sorry for replying late. That is exactly what's happening it is returning a Map. I have not defined any mapping template inside appsync. I'm still stuck regarding how to return data in appsync. – Ahsenriaz Jun 12 '21 at 19:15
  • Checking back in to see if you got things working? – Kelvin Lawrence Aug 06 '21 at 13:47
  • Yes, I found a workaround that made it work. – Ahsenriaz Oct 01 '21 at 14:04

0 Answers0