We’re overhauling Dgraph’s docs to make them clearer and more approachable. If
you notice any issues during this transition or have suggestions, please
let us know.
Schema
To set up a lambda mutation, first you need to define it on your GraphQL schema by using the@lambda
directive.
add
, update
, and delete
are reserved prefixes and they can’t be used to
define Lambda mutations.Author
that creates a new author
with a default reputation
of 3.0
given just the name
:
Resolver
Once the schema is ready, you can define your JavaScript mutation function and add it as resolver in your JS source code. To add the resolver you can use either theaddGraphQLResolvers
or addMultiParentGraphQLResolvers
methods.
A Lambda Mutation resolver can use a combination of
parents
, args
, dql
,
or graphql
inside the function.This example uses
graphql
for the resolver function. You can find additional
resolver examples using dql
in the Lambda queries article, and
using parent
in the Lambda fields article.newAuthor()
lambda function and add it
as resolver:
dql.mutate
to achieve the same results:
Example
Finally, if you execute this lambda mutation a new authorKen Addams
with
reputation=3.0
should be added to the database:
Ken Addams
, you would see: