# Dgraph lambda failed to mutate/query data

**URL:** <https://discuss.dgraph.io/t/dgraph-lambda-failed-to-mutate-query-data/17765>\
**Category:** Dgraph\
**Tags:** kind:bug\
**Created:** [September 12, 2022, 4:51pm UTC](https://discuss.dgraph.io/t/dgraph-lambda-failed-to-mutate-query-data/17765 "2022-09-12T16:51:38Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ann\_Zhang](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/ann_zhang/32/10634_2.png) [@Ann\_Zhang](https://discuss.dgraph.io/u/Ann_Zhang)\
**Post date:** [September 12, 2022, 4:51pm UTC](https://discuss.dgraph.io/t/dgraph-lambda-failed-to-mutate-query-data/17765/1 "2022-09-12T16:51:38Z")

</div>

To facilitate better answering of questions, if you have a question, please fill in the following info. Otherwise, please delete the template.

## What I want to do

Mutate and query data via dgraph lambda

Follow the guidance [[charts/charts/dgraph-lambda at main · dgraph-io/charts · GitHub](https://github.com/dgraph-io/charts/tree/master/charts/dgraph-lambda) ] ([charts/charts/dgraph-lambda at main · dgraph-io/charts · GitHub](https://github.com/dgraph-io/charts/tree/master/charts/dgraph-lambda) ) and solution [http://discuss.hypermode.com/t/helm-install-dgraph-lambda-failed-to-pull-image-dgraph-dgraph-lambda-v1-2-4/17755](http://discuss.hypermode.com/t/helm-install-dgraph-lambda-failed-to-pull-image-dgraph-dgraph-lambda-v1-2-4/17755) to deploy Dgraph and Lambda, I just found another issue. After finishing the last step of uploading schema, pod `my-release-dgraph-alpha-0` crashed with an error message printed in logs of the pods:

> dgraph alpha --my=my-release-dgraph-alpha-0.my-release-dgraph-alpha-headless.default.svc.cluster.local:7080 --zero my-release-dgraph-zero-0.my-release-dgraph-zero-headless.default.svc.cluster.local:5080  
> F0912 16:16:04.948493 1 flags.go:139] superflag: found invalid options in flag: lambda-url=[http://my-lambda-dgraph-lambda.default.svc:80/graphql-worker](http://my-lambda-dgraph-lambda.default.svc:80/graphql-worker).  
> valid options: introspection=true; debug=false; extensions=true; poll-interval=1s;

I delete dgraph/lambda and dgraph/dgraph, modified the **settings** when installing dgraph and redid the following steps.

1. deploy dgraph

```auto
helm install my-release dgraph/dgraph \
  --namespace default \
  --set "alpha.extraEnvs[0].name"=lambda \
  --set "alpha.extraEnvs[0].value"=url=http://my-lambda-dgraph-lambda.default.svc:80/graphql-worker

```

1. deploy lambda

deploy/dev/dgraph/lambda.yaml is the copy from the code on Github tutorial.

```auto
helm install my-lambda dgraph/dgraph-lambda \
  --set image.tag=1.2.4 \
  --namespace default \
  --values deploy/dev/dgraph/lambda.yaml \
  --set "env[0].name"=DGRAPH_URL \
  --set "env[0].value"=http://my-release-dgraph-alpha-headless.default.svc:8080

```

1. forward dgraph port

```auto
kubectl port-forward --namespace default my-release-dgraph-alpha-0 8080:8080

```

1. upload schema  
deploy/dev/dgraph/schema.graphql is the copy from the code on Github tutorial.

```auto
curl http://localhost:8080/admin/schema --upload-file deploy/dev/dgraph/schema.graphql

```

Now everything goes well, run:

```auto
kubectl get pods

```

it lists:

> NAME READY STATUS RESTARTS AGE  
> my-lambda-dgraph-lambda-5969cf5cbb-ptssv 1/1 Running 0 2m56s  
> my-release-dgraph-alpha-0 1/1 Running 0 5m4s  
> my-release-dgraph-alpha-1 1/1 Running 0 4m45s  
> my-release-dgraph-alpha-2 1/1 Running 0 4m25s  
> my-release-dgraph-zero-0 1/1 Running 0 5m4s  
> my-release-dgraph-zero-1 1/1 Running 0 4m45s  
> my-release-dgraph-zero-2 1/1 Running 0 4m32s

1. Test  
Add Author GraphQL body:

```auto
mutation MyMutation {
  addAuthor(input: {name: "AnnZhang"}) {
    numUids
  }
}

```

it suceeded. **However, I tried the lambda resolver mutation like this, it failed.**

```auto
mutation MyMutation {
  newAuthor(name: "AnnZ")
}

```

> error message:  
> “errors”: [  
> {  
> “message”: “Evaluation of custom field failed because external request returned an error: unexpected error with: 400 for field: newAuthor within type: Mutation.”,  
> “locations”: [  
> {  
> “line”: 2,  
> “column”: 3  
> }  
> ]  
> }  
> ],

---

<div class="post-metadata">

**Author:** ![Ann\_Zhang](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/ann_zhang/32/10634_2.png) [@Ann\_Zhang](https://discuss.dgraph.io/u/Ann_Zhang)\
**Post date:** [September 12, 2022, 4:59pm UTC](https://discuss.dgraph.io/t/dgraph-lambda-failed-to-mutate-query-data/17765/2 "2022-09-12T16:59:07Z")

</div>

1. list all pods

> NAME READY STATUS RESTARTS AGE  
> my-lambda-dgraph-lambda-5969cf5cbb-fpk8s 1/1 Running 0 11s  
> my-release-dgraph-alpha-0 1/1 Running 0 29m  
> my-release-dgraph-alpha-1 1/1 Running 0 29m  
> my-release-dgraph-alpha-2 1/1 Running 0 28m  
> my-release-dgraph-zero-0 1/1 Running 0 29m  
> my-release-dgraph-zero-1 1/1 Running 0 29m  
> my-release-dgraph-zero-2 1/1 Running 0 29m

1. get logs of pod `my-lambda-dgraph-lambda-5969cf5cbb-fpk8s`

> dgraph-lambda@1.2.0 start /app  
> pm2-runtime start ecosystem.config.js  
> 2022-09-12T16:54:00: PM2 log: Launching in no daemon mode  
> 2022-09-12T16:54:00: PM2 log: [Watch] Start watching dgraph-lambda  
> 2022-09-12T16:54:00: PM2 log: App [dgraph-lambda:0] starting in -cluster mode-  
> 2022-09-12T16:54:00: PM2 log: App [dgraph-lambda:0] online  
> 2022-09-12T16:54:00: PM2 log: [Watch] Start watching dgraph-lambda  
> 2022-09-12T16:54:00: PM2 log: App [dgraph-lambda:1] starting in -cluster mode-  
> 2022-09-12T16:54:00: PM2 log: App [dgraph-lambda:1] online  
> 2022-09-12T16:54:00: PM2 log: [Watch] Start watching dgraph-lambda  
> 2022-09-12T16:54:00: PM2 log: App [dgraph-lambda:2] starting in -cluster mode-  
> 2022-09-12T16:54:00: PM2 log: App [dgraph-lambda:2] online  
> 2022-09-12T16:54:00: PM2 log: [Watch] Start watching dgraph-lambda  
> 2022-09-12T16:54:00: PM2 log: App [dgraph-lambda:3] starting in -cluster mode-  
> 2022-09-12T16:54:01: PM2 log: App [dgraph-lambda:3] online  
> Server Listening on port 8686!  
> Server Listening on port 8686!  
> Server Listening on port 8686!  
> Server Listening on port 8686!

**I tried the same script on Dgraph cloud, the lambda resolver worked well.** I have no idea why it doesn’t work from this approach.

---

<div class="post-metadata">

**Author:** ![matthewmcneely](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/matthewmcneely/32/4774_2.png) [@matthewmcneely](https://discuss.dgraph.io/u/matthewmcneely)\
**Post date:** [September 12, 2022, 5:10pm UTC](https://discuss.dgraph.io/t/dgraph-lambda-failed-to-mutate-query-data/17765/3 "2022-09-12T17:10:07Z")

</div>

OK, that’s not very helpful is it?

Can you share the JS code for the lambda and the full mutation query you’re making against it?

---

<div class="post-metadata">

**Author:** ![Ann\_Zhang](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/ann_zhang/32/10634_2.png) [@Ann\_Zhang](https://discuss.dgraph.io/u/Ann_Zhang)\
**Post date:** [September 12, 2022, 5:13pm UTC](https://discuss.dgraph.io/t/dgraph-lambda-failed-to-mutate-query-data/17765/4 "2022-09-12T17:13:45Z")

</div>

**The JS code:**

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

    async function newAuthor({args, graphql}) {
        // lets give every new author a reputation of 3 by default
        const results = await graphql(`mutation ($name: String!) {
            addAuthor(input: [{name: $name, reputation: 3.0 }]) {
                author {
                    id
                    reputation
                }
            }
        }`, {"name": args.name})
        return results.data.addAuthor.author[0].id
    }

    self.addGraphQLResolvers({
        "Query.authorsByName": authorsByName,
        "Mutation.newAuthor": newAuthor
    })

```

**full mutation query:** screenshot

 ![Screen Shot 2022-09-12 at 1.12.55 PM](https://canada1.discourse-cdn.com/flex007/uploads/dgraph/original/2X/e/e11c939df5cdf189c36e42dc2714975610436309.png)

---

<div class="post-metadata">

**Author:** ![Ann\_Zhang](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/ann_zhang/32/10634_2.png) [@Ann\_Zhang](https://discuss.dgraph.io/u/Ann_Zhang)\
**Post date:** [September 12, 2022, 5:22pm UTC](https://discuss.dgraph.io/t/dgraph-lambda-failed-to-mutate-query-data/17765/5 "2022-09-12T17:22:31Z")

</div>

@ [matthewmcneely](http://discuss.hypermode.com/u/matthewmcneely)  
On cloud, the script goes like this, the content is untouched.

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

async function newAuthor({args, graphql}) {
    // lets give every new author a reputation of 3 by default
    const results = await graphql(`mutation ($name: String!) {
        addAuthor(input: [{name: $name, reputation: 3.0 }]) {
            author {
                id
                reputation
            }
        }
    }`, {"name": args.name})
    return results.data.addAuthor.author[0].id
}

self.addGraphQLResolvers({
    "Query.authorsByName": authorsByName,
    "Mutation.newAuthor": newAuthor
})

```

Mutation succeeded:

 ![Screen Shot 2022-09-12 at 1.21.32 PM](https://canada1.discourse-cdn.com/flex007/uploads/dgraph/original/2X/9/9a3ee9befa36e4bd1d00279c13398561d87058aa.png)

---

<div class="post-metadata">

**Author:** ![jdgamble555](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/jdgamble555/32/7503_2.png) [@jdgamble555](https://discuss.dgraph.io/u/jdgamble555)\
**Post date:** [September 12, 2022, 5:53pm UTC](https://discuss.dgraph.io/t/dgraph-lambda-failed-to-mutate-query-data/17765/6 "2022-09-12T17:53:03Z")

</div>

I would put the first one in custom dql queries instead of lambdas. Much easier to manage, plus you can add subscription support. Unfortunately, mutations need lambdas.

[https://dgraph.io/docs/graphql/custom/dql/](https://dgraph.io/docs/graphql/custom/dql/)

J

---

<div class="post-metadata">

**Author:** ![Ann\_Zhang](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/ann_zhang/32/10634_2.png) [@Ann\_Zhang](https://discuss.dgraph.io/u/Ann_Zhang)\
**Post date:** [September 12, 2022, 6:05pm UTC](https://discuss.dgraph.io/t/dgraph-lambda-failed-to-mutate-query-data/17765/7 "2022-09-12T18:05:43Z")

</div>

Thanks [jdgamble555](http://discuss.hypermode.com/u/jdgamble555). Unfortunately I have to use mutation. It seems that Alpha-0 doesn’t recognize the existence of lambda at all. Each time I sent the mutate request, alpha-0 printed a log `Got GraphQL request over HTTP` which proves that alpha-0 received it correctly, but nothing new came up in lambda container log. I tried docker compose to start dgraph alpha, zero, and lambda, it worked.  
docker-compose.yml

```auto
version: "3.2"
services:
  zero:
    image: dgraph/dgraph:v21.12.0
    volumes:
      - ${PWD}/dgraph/data:/dgraph
    ports:
      - 5080:5080
      - 6080:6080
    restart: on-failure
    command: dgraph zero --my=zero:5080 --telemetry sentry=false --telemetry reports=false
  alpha:
    image: dgraph/dgraph:v21.12.0
    volumes:
      - ${PWD}/dgraph/data:/dgraph
    ports:
      - 8080:8080
      - 9080:9080
    restart: on-failure
    command: dgraph alpha --my=alpha:7080 --zero=zero:5080 --security whitelist=0.0.0.0/0 --telemetry sentry=false --telemetry reports=false --lambda url=http://dgraph_lambda:8686/graphql-worker

  dgraph_lambda:
    image: dgraph/dgraph-lambda:latest
    depends_on:
      - zero
      - alpha
    ports:
      - "8686:8686"
    environment:
      DGRAPH_URL: http://alpha:8080
    volumes:
      - ${PWD}/dgraph/gql/script.js:/app/script/script.js:ro

```

---

<div class="post-metadata">

**Author:** ![matthewmcneely](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/matthewmcneely/32/4774_2.png) [@matthewmcneely](https://discuss.dgraph.io/u/matthewmcneely)\
**Post date:** [September 12, 2022, 7:23pm UTC](https://discuss.dgraph.io/t/dgraph-lambda-failed-to-mutate-query-data/17765/8 "2022-09-12T19:23:04Z")

</div>

Right, I just finished trying in a local docker-compose setup and it worked. FYI, I’d recommend testing against v21.03.2 (that’s what’s “officially” supported and what the cloud runs)

Can you send me the Author type as is in your SDL?

---

<div class="post-metadata">

**Author:** ![Ann\_Zhang](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/ann_zhang/32/10634_2.png) [@Ann\_Zhang](https://discuss.dgraph.io/u/Ann_Zhang)\
**Post date:** [September 12, 2022, 7:26pm UTC](https://discuss.dgraph.io/t/dgraph-lambda-failed-to-mutate-query-data/17765/9 "2022-09-12T19:26:07Z")

</div>

> [@matthewmcneely](#):
>
> SDL

The schema:

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

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

type Mutation {
    newAuthor(name: String!): ID! @lambda
}

```

---

<div class="post-metadata">

**Author:** ![Ann\_Zhang](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/ann_zhang/32/10634_2.png) [@Ann\_Zhang](https://discuss.dgraph.io/u/Ann_Zhang)\
**Post date:** [September 12, 2022, 7:31pm UTC](https://discuss.dgraph.io/t/dgraph-lambda-failed-to-mutate-query-data/17765/10 "2022-09-12T19:31:00Z")

</div>

someone posted a link [http://discuss.hypermode.com/t/zion-v21-12-documentation-and-setting-up-a-lambda-server/16396/2](http://discuss.hypermode.com/t/zion-v21-12-documentation-and-setting-up-a-lambda-server/16396/2) which suggested using /admin api to update lambda script. Is it still working on self-host dgraph like this case? if yes, can you please provide a sample as a guidance of correctly using that api to update the lambda script ? Thanks.

---

<div class="post-metadata">

**Author:** ![matthewmcneely](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/matthewmcneely/32/4774_2.png) [@matthewmcneely](https://discuss.dgraph.io/u/matthewmcneely)\
**Post date:** [September 12, 2022, 7:49pm UTC](https://discuss.dgraph.io/t/dgraph-lambda-failed-to-mutate-query-data/17765/11 "2022-09-12T19:49:42Z")

</div>

That (the updatelamdbascript) was a 20.12 feature, not up on cloud. I’ll try to replicate the issue in a cloud instance myself.

---

<div class="post-metadata">

**Author:** ![Ann\_Zhang](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/ann_zhang/32/10634_2.png) [@Ann\_Zhang](https://discuss.dgraph.io/u/Ann_Zhang)\
**Post date:** [September 12, 2022, 7:53pm UTC](https://discuss.dgraph.io/t/dgraph-lambda-failed-to-mutate-query-data/17765/12 "2022-09-12T19:53:28Z")

</div>

I just downgraded dgraph image version to v21.03.2 from v21.12.0 to replicate all the steps above, the error code for the same customized mutation turned to 500 from 400:

> ```
> "errors": [
> {
> "message": "Evaluation of custom field failed because external request returned an error: unexpected error with: 500 for field: newAuthor within type: Mutation.",
> "locations": [
> {
> "line": 2,
> "column": 3
> }
> ]
> }
> ],
> 
> ```

lambda container error message:

> TypeError: Only absolute URLs are supported  
> at getNodeRequestOptions (/app/node\_modules/node-fetch/lib/index.js:1305:9)  
> at /app/node\_modules/node-fetch/lib/index.js:1410:19  
> at new Promise ()  
> at Function.fetch [as default] (/app/node\_modules/node-fetch/lib/index.js:1407:9)  
> at Object.graphql (/app/src/dgraph.ts:9:31)  
> at graphql (/app/src/evaluate-script.ts:87:89)  
> at newAuthor (evalmachine.:14:27)  
> at /app/src/evaluate-script.ts:31:59  
> at Array.map ()  
> at GraphQLResolverEventTarget. (/app/src/evaluate-script.ts:31:45)

---

<div class="post-metadata">

**Author:** ![matthewmcneely](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/matthewmcneely/32/4774_2.png) [@matthewmcneely](https://discuss.dgraph.io/u/matthewmcneely)\
**Post date:** [September 12, 2022, 7:58pm UTC](https://discuss.dgraph.io/t/dgraph-lambda-failed-to-mutate-query-data/17765/13 "2022-09-12T19:58:25Z")

</div>

It’s working for me in the cloud, the schema

```auto
type Author {
  id: ID!
  name: String
  reputation: Float
}

type Mutation {
    newAuthor(name: String!): ID! @lambda
}

```

The script:

```auto
async function newAuthor({args, graphql}) {
    // lets give every new author a reputation of 3 by default
    const results = await graphql(`mutation ($name: String!) {
        addAuthor(input: [{name: $name, reputation: 3.0 }]) {
            author {
                id
                reputation
            }
        }
    }`, {"name": args.name})
    console.log('results--------------\n', results)
    return results.data.addAuthor.author[0].id
}

self.addGraphQLResolvers({
    "Mutation.newAuthor": newAuthor
})

```

The mutation:

```auto
mutation {
	newAuthor(name: "Foo")
}

```

Query results

```auto
{
  "data": {
    "queryAuthor": [
      {
        "id": "0xfffd8d6ab27a9454",
        "name": "Foo",
        "reputation": 3
      }
    ]
  }
<snip>
}

```

---

<div class="post-metadata">

**Author:** ![Ann\_Zhang](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/ann_zhang/32/10634_2.png) [@Ann\_Zhang](https://discuss.dgraph.io/u/Ann_Zhang)\
**Post date:** [September 12, 2022, 8:04pm UTC](https://discuss.dgraph.io/t/dgraph-lambda-failed-to-mutate-query-data/17765/14 "2022-09-12T20:04:59Z")

</div>

> [@matthewmcneely](#):
>
> ```auto
> async function newAuthor({args, graphql}) {
> // lets give every new author a reputation of 3 by default
> const results = await graphql(`mutation ($name: String!) {
> addAuthor(input: [{name: $name, reputation: 3.0 }]) {
> author {
> id
> reputation
> }
> }
> }`, {"name": args.name})
> console.log('results--------------\n', results)
> return results.data.addAuthor.author[0].id
> }
> 
> self.addGraphQLResolvers({
> "Mutation.newAuthor": newAuthor
> })
> 
> ```

It works for me as well on Cloud. It is frustrating that it doesn’t work on self-hosted cluster.

---

<div class="post-metadata">

**Author:** ![matthewmcneely](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/matthewmcneely/32/4774_2.png) [@matthewmcneely](https://discuss.dgraph.io/u/matthewmcneely)\
**Post date:** [September 12, 2022, 8:08pm UTC](https://discuss.dgraph.io/t/dgraph-lambda-failed-to-mutate-query-data/17765/15 "2022-09-12T20:08:13Z")

</div>

Oh, wait… I thought you were having an issue on a cloud instance.

I’ll try to recreate it locally.

---

<div class="post-metadata">

**Author:** ![Ann\_Zhang](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/ann_zhang/32/10634_2.png) [@Ann\_Zhang](https://discuss.dgraph.io/u/Ann_Zhang)\
**Post date:** [September 12, 2022, 8:11pm UTC](https://discuss.dgraph.io/t/dgraph-lambda-failed-to-mutate-query-data/17765/16 "2022-09-12T20:11:15Z")

</div>

[matthewmcneely](http://discuss.hypermode.com/u/matthewmcneely) Cloud works fine. Local deploy using docker-compose with Dgraph v21.12.0 works as well. The core issue is deploying to AWS via helm install. It seems that Lambda Javascript in yaml file was never uploaded successfully. For dgraph v21.12.0 there wasn’t even an error in lambda container log but a response code 400, for v21.03.2 the error is TypeError: Only absolute URLs are supported…with response code 500.

---

<div class="post-metadata">

**Author:** ![Ann\_Zhang](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/ann_zhang/32/10634_2.png) [@Ann\_Zhang](https://discuss.dgraph.io/u/Ann_Zhang)\
**Post date:** [September 12, 2022, 10:11pm UTC](https://discuss.dgraph.io/t/dgraph-lambda-failed-to-mutate-query-data/17765/17 "2022-09-12T22:11:30Z")

</div>

I figured out how to resolve it. Thanks to [http://discuss.hypermode.com/t/how-to-setup-lambda-server/16585/4?u=ann\_zhang](http://discuss.hypermode.com/t/how-to-setup-lambda-server/16585/4)

The javascript in my-lambda.yaml of [https://github.com/dgraph-io/charts/tree/master/charts/dgraph-lambda](https://github.com/dgraph-io/charts/tree/master/charts/dgraph-lambda) was never uploaded correctly though, hope it can be fixed.

Switch to dgraph v21.12.0. After deploying Dgraph and Lambda resolver, use the following request to update to Lambda Script.  
**URL: `http://localhost:8080/admin`**  
**request method: `post`**  
**GraphQL body:**

```auto
mutation{
	updateLambdaScript(input:{set:{script:
    """async function authorsByName({args, dql}) {
            const results = await dql.query(`query queryAuthor($name: string) {
                queryAuthor(func: type(Author)) @filter(eq(Author.name, $name)) {
                    name: Author.name
                    dob: Author.dob
                    reputation: Author.reputation
                }
            }`, {"$name": args.name})
            return results.data.queryAuthor
        }

        async function newAuthor({args, graphql}) {
            // lets give every new author a reputation of 3 by default
            const results = await graphql(`mutation ($name: String!) {
                addAuthor(input: [{name: $name, reputation: 3.0 }]) {
                    author {
                        id
                        reputation
                    }
                }
            }`, {"name": args.name})
            return results.data.addAuthor.author[0].id
        }

        self.addGraphQLResolvers({
            "Query.authorsByName": authorsByName,
            "Mutation.newAuthor": newAuthor
        })
    """
	
	}}){
		lambdaScript{script}
	}
}

```

Response:

```auto
{
    "data": {
        "updateLambdaScript": {
            "lambdaScript": {
                "script": "async function authorsByName({args, dql}) {\n const results = await dql.query(`query queryAuthor($name: string) {\n queryAuthor(func: type(Author)) @filter(eq(Author.name, $name)) {\n name: Author.name\n dob: Author.dob\n reputation: Author.reputation\n }\n }`, {\"$name\": args.name})\n return results.data.queryAuthor\n}\n\nasync function newAuthor({args, graphql}) {\n // lets give every new author a reputation of 3 by default\n const results = await graphql(`mutation ($name: String!) {\n addAuthor(input: [{name: $name, reputation: 3.0 }]) {\n author {\n id\n reputation\n }\n }\n }`, {\"name\": args.name})\n return results.data.addAuthor.author[0].id\n}\n\nself.addGraphQLResolvers({\n \"Query.authorsByName\": authorsByName,\n \"Mutation.newAuthor\": newAuthor\n})"
            }
        }
    },
    "extensions": {
        "tracing": {
            "version": 1,
            "startTime": "2022-09-12T22:00:53.209702215Z",
            "endTime": "2022-09-12T22:00:53.212745638Z",
            "duration": 3043444
        }
    }
}

```

**Test mutation:**

```auto
mutation MyMutation {
  newAuthor(name: "AnnZ")
}

```

Response:

```auto
{
    "data": {
        "newAuthor": "0x3"
    },
    "extensions": {
        "tracing": {
            "version": 1,
            "startTime": "2022-09-12T22:01:04.270299555Z",
            "endTime": "2022-09-12T22:01:04.296470949Z",
            "duration": 26171399
        }
    }
}

```
