jdgamble555
(Jonathan Gamble)
November 25, 2021, 4:24am
1
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: 'test@test.com'
}
}
};
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":"test@test.com"}}}
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
@minhaj Could you guys add JSON Mutation Format support to lambdas?
There are many use cases for this.
Thanks,
J
After hours and hours, finally got it like so:
const args = `
{
set {
_:blank-0 <Post.name> "${args.name}" .
_:blank-0 <Post.description> "${args.description}" .
_:blank-0 <Post.published> "${args.published}" .
_:blank-0 <dgraph.type> "Post" .
}
}
`;
Note: dql requires the newlines, unlike graphql.
const results = await dql.mutate(args);
While I am currently affected with this,
Regarding #1 I would suggest that graphql should accept a different token from within lambdas.
I can get or generate a new auth token in the lambda, slight inconvenience, but it can be done. and then if I can pass that new token in the graphql requests, it would allow me to send admin tokens.
Also would recommend if we can allow having environment variables in the lambdas (I am going to create a new topic for it). so then I can add the admin credential…
jdgamble555
(Jonathan Gamble)
November 26, 2021, 3:55am
2
@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
MichelDiz
(Michel Diz)
November 26, 2021, 4:37am
3
It should be in the cloud. Try double quotes instead.
jdgamble555
(Jonathan Gamble)
November 26, 2021, 5:22am
4
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
MichelDiz
(Michel Diz)
November 26, 2021, 5:24am
5
jdgamble555:
[object Object]
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.
jdgamble555
(Jonathan Gamble)
November 26, 2021, 5:28am
6
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
MichelDiz
(Michel Diz)
November 26, 2021, 5:17pm
7
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);
}
jdgamble555
(Jonathan Gamble)
November 26, 2021, 10:56pm
8
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
jdgamble555
(Jonathan Gamble)
November 28, 2021, 11:02pm
9
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
MichelDiz
(Michel Diz)
November 28, 2021, 11:04pm
10
I can guarantee the commit but am not sure about the deployment into the cloud.
jdgamble555
(Jonathan Gamble)
November 28, 2021, 11:18pm
11
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
MichelDiz
(Michel Diz)
November 29, 2021, 12:39am
12
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.
jdgamble555
(Jonathan Gamble)
November 29, 2021, 1:08am
13
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.
MichelDiz
(Michel Diz)
November 29, 2021, 3:39am
14
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
jdgamble555
(Jonathan Gamble)
November 29, 2021, 3:47am
15
Yeah, It needed to be updated anyway…
I wasn’t sure if it compiled to string()
or something in js.
Will test tomorrow…
J
MichelDiz
(Michel Diz)
November 29, 2021, 11:02pm
16
The lambda repo was released by @dmai - NPM and Docker hub.
@jdgamble555 can you test it out?
jdgamble555
(Jonathan Gamble)
November 30, 2021, 1:11am
17
@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
MichelDiz
(Michel Diz)
November 30, 2021, 1:20am
18
If you weren’t using Docker, there’s no need to use it now. Update only the dependency you were using.
jdgamble555
(Jonathan Gamble)
November 30, 2021, 1:36am
19
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
jdgamble555
(Jonathan Gamble)
December 1, 2021, 1:26pm
20
Ummm @MichelDiz @dmai - We can’t figure out if this was deployed to the could or not?
J