Run a dql mutation in slash dgraph lambda

How can I run a dql mutation in a slash dgraph lambda? If I have something like this:

async function newPost({args, dql}) {

  const newArgs = {
    name: args.name,
    description: args.description,
    nameKebab: args.name.replace(/\s/g,"-").toLowerCase(),
    published: args.published
  };

  const results = await dql.query(`mutation addPost($post: AddPostInput!) {
  addPost(input: [$post]) {
    post {
      id
      name
      description
      published
    }
  }
}`, {"post": newArgs});
  console.log(JSON.stringify(results.data));
  return results.data.addPost.post[0].id
}

I don’t believe dql.mutation works. Am I supposed to run an upsert instead of a mutation?

This posts is talking about @custom mutations, not lambdas, but I assume the premise is the same…

How do I run an upsert if that is the case dql.upsert?.. and with an upsert do I just run a blank query?

Thanks,
J

Hi @jdgamble555 , you can use dql mutation in lamda as given in docs
https://dgraph.io/docs/master/graphql/lambda/mutation/
Let me know if it doesn’t clear your doubt.

@JatinDevDG Hi. The link you sent uses graphql, not dql.

I need to use dql mutation.

It is dql.mutate(): dgraph-lambda/slash-graphql-lambda-types/types.d.ts at master · dgraph-io/dgraph-lambda · GitHub

BTW, the thing you have written as a mutation in dql.query(), is actually a GraphQL mutation, not a DQL one:

Sorry, we do not have this bit in our docs. We will update our docs to reflect this.

Thanks

1 Like