Lambda JSON Mutation

Hi, I thought that my PR for JSON Mutations in lambdas was accepted back in April.

It looks like it has been implemented here. However, when I run this code in my lambda:

async function testLambdaHook({ dql }) {

    const args = {
        set: {
            User: {
                name: 'test',
                email: '[email protected]'
            }
        }
    };

    console.log(JSON.stringify(args));
    const r = await dql.mutate(args);
    console.log(r);
}

and I get this error:

Thu, 25 Nov 2021 04:20:26 GMT
}
Thu, 25 Nov 2021 04:20:26 GMT
]
Thu, 25 Nov 2021 04:20:26 GMT
}
Thu, 25 Nov 2021 04:20:26 GMT
extensions: [Object]
Thu, 25 Nov 2021 04:20:26 GMT
message: "while lexing [object Object] at line 1 
column 0: Unexpected character while identifying mutation block: U+005B '['",
Thu, 25 Nov 2021 04:20:26 GMT
{
Thu, 25 Nov 2021 04:20:26 GMT
errors: [
Thu, 25 Nov 2021 04:20:26 GMT
{
Thu, 25 Nov 2021 04:20:26 GMT
{"set":{"User":{"name":"test","email":"[email protected]"}}}
Thu, 25 Nov 2021 04:20:26 GMT
Received event $webhook
Thu, 25 Nov 2021 04:20:22 GMT
Specializing Container
Thu, 25 Nov 2021 04:20:21 GMT
Starting Server On Port 8888

Has this feature not been added to Dgraph Cloud yet?

Thanks,

J

Related

@MichelDiz - It looks like you committed this, would it be on the latest version of the cloud? If not there may be an error somewhere, unless my basic code is off.

Thanks,

J

It should be in the cloud. Try double quotes instead.

Hmm, I simplified it even more,

async function myLambdaHook({ dql }) {

  const args = {
    "Feature.name": "turtle",
    "Feature.url": "slow",
    "dgraph.type": "Feature"
  };

  const r = await dql.mutate(args);
  console.log(r);
}

and I get this same error:

message: "while lexing [object Object] at line 1 column 0: 
Unexpected character while identifying mutation block: U+005B '['",

There is no [ in my code at all, which is the weirdest part.

J

This looks like a JS parsing error. Feels like you need to or Stringfy something (e.g the obj) or convert the object to JSON.

That is what this is supposed to do.

Unless I am missing something?

I wonder if this could be the problem where the typing is off?

mutate: (s: string) => Promise<GraphQLResponse>;

Not sure how to properly test this?

J

Try this (I did not try this code)

async function testLambdaHook({ dql }) {

    const args = {
        set: [
      {
         "Feature.name":"turtle",
         "Feature.url":"slow",
         "dgraph.type":"Feature"
      }
   ]
    };
    let obj = JSON.stringify(args) //Just in case

    console.log(JSON.stringify(args));
    const r = await dql.mutate({ mutation: JSON.parse(obj), commitNow: true });
    console.log(r);
}

No, I got the exact same error.

The types file needs to be updated, but since typescript compiles to js, not sure if that would be the problem. I tried both with and without the stringify, but again, that is already done inside the function, so it does not change the error.

Are we 100% sure it committed to v21.03.0-78-ge4ad0b113 or earlier?

Thanks,

J

I would do a PR request on this to fix it, but I need to make sure it is committed correctly. @MichelDiz can you double check this?

J

I can guarantee the commit but am not sure about the deployment into the cloud.

That is what I meant. How can I check the lambda version? Or even better, how can we get the lambda versions updated to the cloud (I would think this would be done when there is a new version — 21.03 —, but I could see how this would have gotten skipped over…

J

I think the way to “check” this is look if the image exists in Docker Hub e.g. dgraph/dgraph-lambda Tags | Docker Hub.

The PR mentioned in the main post was before the latest release.

Ok thanks. It makes no sense why it doesn’t work. It looks like there was no exact test on it. Other than spinning up my own proper server and testing a basic mutation with println, I don’t know how to test it.

Any ideas?

Thanks,

J


I just made a PR for the typing problem. Hopefully that fixes the problem.

A TS type should fix? why? It should work with vanilla JS, not TS.

PS. Looks like that a way to test it is just by running the code with NPM locally running a GraphQL instance. Feels like it is just a NPM server in the docker image, it isn’t a fancy go lang build or something.

Just clone it and run npm run start

Yeah, It needed to be updated anyway…

I wasn’t sure if it compiled to string() or something in js.

Will test tomorrow…

J

The lambda repo was released by @dmai - NPM and Docker hub.

@jdgamble555 can you test it out?

@MichelDiz

I imagine I need to run DGraph Database on a Docker too (which I have never done)? How else would I test it without a database. There is a reason I use DGraph Cloud, I don’t want to mess with server configurations. I have no idea how to configure it. Also I would need to let the database know which port the DGraph lambda server is on?

You can see the lambda server is running, but now what? I can’t get the dgraph database server to even run, as it just exits immediately after I run it.



This is all above my head. Surely you guys can test this better than I can…

J

If you weren’t using Docker, there’s no need to use it now. Update only the dependency you were using.

I am using DGraph cloud, and my PR does not seem to be working on it. The goal of this thread is to figure out why.

So, are we sure the PR is up-to-date on the cloud version? If so, what next? If not, how do I get it updated?

J

2 Likes

Ummm @MichelDiz @dmai - We can’t figure out if this was deployed to the could or not?

J