Lambda Mutations
Ready to use lambdas for mutations? This documentation takes you through the schemas, resolvers, and examples.
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.
For example, to define a lambda mutation for 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 the addGraphQLResolvers
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.
For example, to define the JavaScript newAuthor()
lambda function and add it
as resolver:
Alternatively, you can use dql.mutate
to achieve the same results:
Example
Finally, if you execute this lambda mutation a new author Ken Addams
with
reputation=3.0
should be added to the database:
Afterwards, if you query the GraphQL database for Ken Addams
, you would see:
Was this page helpful?