Ask a Question

Lambda Queries


To set up a lambda query, first you need to define it on your GraphQL schema by using the @lambda directive.

Note get, query, and aggregate are reserved prefixes and they can’t be used to define Lambda queries.

For example, to define a lambda query for Author that finds out authors given an author’s name:

type Author {
    id: ID!
    name: String! @search(by: [hash, trigram])
    dob: DateTime
    reputation: Float

type Query {
    authorsByName(name: String!): [Author] @lambda


Once the schema is ready, you can define your JavaScript query function and add it as resolver in your JS source code. To add the resolver you can use either the addGraphQLResolvers or addMultiParentGraphQLResolvers methods.

Note A Lambda Query resolver can use a combination of parents, args, dql, or graphql inside the function.
Tip This example uses dql for the resolver function. You can find additional resolver examples using parent in the Lambda fields article, and using graphql in the Lambda mutations article.

For example, to define the JavaScript authorsByName() lambda function and add it as resolver:

async function authorsByName({args, dql}) {
    const results = await dql.query(`query queryAuthor($name: string) {
        queryAuthor(func: type(Author)) @filter(eq(, $name)) {
            dob: Author.dob
            reputation: Author.reputation
    }`, {"$name":})

    "Query.authorsByName": authorsByName,


Finally, if you execute this lambda query

query {
	authorsByName(name: "Ann Author") {

You should see a response such as

	"authorsByName": [
			"name":"Ann Author",