Lambda provides a way to write custom logic in JavaScript, integrate it with your GraphQL schema, and execute it using the GraphQL API in a few easy steps.
@lambda directive and thus tell
Dgraph where to apply custom JavaScript logic.
self.addGraphQLResolversself.addMultiParentGraphQLResolversself.addGraphQLResolvers and self.addMultiParentGraphQLResolvers
can be called multiple times in your resolver code.self.addGraphQLResolvers method takes an object as an argument, which maps
a resolver name to the resolver function that implements it. The resolver
functions registered using self.addGraphQLResolvers receive
{ parent, args, graphql, dql } as argument:
parent, the parent object for which to resolve the current lambda field
registered using addGraphQLResolver. The parent receives all immediate
fields of that object, whether or not they were actually queried. Available
only for types and interfaces (null for queries and mutations)args, the set of arguments for lambda queries and mutationsgraphql, a function to execute auto-generated GraphQL API calls from the
lambda server. The userβs auth header is passed back to the graphql
function, so this can be used securelydql, provides an API to execute DQL from the lambda serverauthHeader, provides the JWT key and value of the auth header passed from
the clientaddGraphQLResolvers can be represented with the following TypeScript
types:
self.addGraphQLResolvers is the default choice for registering resolvers
when the result of the lambda for each parent is independent of other parents.myTypeResolver registered for
the customField field in MyType returns a string because the return type of
that field in the GraphQL schema is String:
graphql call:
self.addMultiParentGraphQLResolvers is useful in scenarios where you want
to perform computations involving all the parents returned from Dgraph for a
lambda field. This is useful in two scenarios:
{ parents, args, graphql, dql } as argument:
parents, a list of parent objects for which to resolve the current lambda
field registered using addMultiParentGraphQLResolvers. Available only for
types and interfaces (null for queries and mutations)args, the set of arguments for lambda queries and mutations (null for
types and interfaces)graphql, a function to execute auto-generated GraphQL API calls from the
lambda serverdql, provides an API to execute DQL from the lambda serverauthHeader, provides the JWT key and value of the auth header passed from
the clientaddMultiParentGraphQLResolvers can be represented with the following
TypeScript types:
rank() registered for the
rank field in Author, returns a list of integers because the return type of
that field in the GraphQL schema is Int:
dql call:
graphql call and manually overrides the
authHeader provided by the client:
@lambda directive, see: