# Add-webhook on deep mutations

**URL:** <https://discuss.dgraph.io/t/add-webhook-on-deep-mutations/13874>\
**Category:** GraphQL\
**Tags:** kind:enhancement, status:accepted, ticket:created\
**Created:** [April 26, 2021, 5:08am UTC](https://discuss.dgraph.io/t/add-webhook-on-deep-mutations/13874 "2021-04-26T05:08:51Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![iyinoluwaayoola](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/iyinoluwaayoola/32/4282_2.png) [@iyinoluwaayoola](https://discuss.dgraph.io/u/iyinoluwaayoola)\
**Post date:** [April 26, 2021, 5:08am UTC](https://discuss.dgraph.io/t/add-webhook-on-deep-mutations/13874/1 "2021-04-26T05:08:51Z")

</div>

According to the docs [here](https://dgraph.io/docs/graphql/mutations/deep/):

> You can perform deep mutations at multiple levels. Deep mutations do not alter linked objects, but they can **add deeply-nested new objects** …

Since deep mutations can add new objects, shouldn’t it trigger my registered add-webhook on the nested object? But this is not the case for me.

@abhimanyusinghgaur, is this the expected behaviour?

---

<div class="post-metadata">

**Author:** ![abhimanyusinghgaur](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/abhimanyusinghgaur/32/2980_2.png) [@abhimanyusinghgaur](https://discuss.dgraph.io/u/abhimanyusinghgaur)\
**Post date:** [April 26, 2021, 7:02am UTC](https://discuss.dgraph.io/t/add-webhook-on-deep-mutations/13874/2 "2021-04-26T07:02:32Z")

</div>

> [@iyinoluwaayoola](#):
>
> Since deep mutations can add new objects, shouldn’t it trigger my registered add-webhook on the nested object?

No. For example, if you have a schema like:

```auto
type Author @lambdaOnMutate(add: true) {
  ...
  posts: [Post]
}

type Post @lambdaOnMutate(add: true) {
  ...
  author: Author @hasInverse(field: posts)
}

```

and you are doing an `addAuthor` with nested posts, then the webhook registered for `Author.add` will be triggered, not the one on `Post.add`. The `Author.add` webhook will get an event that contains the input that `addAuthor` received, including the nested posts.

If `Author.add` isn’t getting triggered, then it might be a bug.

---

<div class="post-metadata">

**Author:** ![amaster507](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/amaster507/32/4123_2.png) [@amaster507](https://discuss.dgraph.io/u/amaster507)\
**Post date:** [April 26, 2021, 7:16am UTC](https://discuss.dgraph.io/t/add-webhook-on-deep-mutations/13874/3 "2021-04-26T07:16:26Z")

</div>

oh ☹ That would not be as I expected it either then.

Use Case Scenario, I want to run a spellcheck webhook every time a new post is added. A new post can be added when adding a new tag, new category, new user, new comment, etc. So I have to then create the same webhook for every single parent object and look for deeply nested data and run the correct webhook. That is not what I was expecting this does. I (and at least another user) expected that this ran the webhook for whenever that data is added.

But, I guess that makes sense, the webhook is tied directly to the generated mutation (lambdaOnMutate), not the type as it appears in the schema. Just more extra steps to get what we need then.

The main problem here is schema scale. I setup up webhooks and then scale my schema adding more types that can create new posts as their children and forget to add the webhooks for those mutations watching for children and running my existing webhooks, then it easily becomes something that I just don’t do. I hope this can be expanded to cover the use case presented to run everytime the type is added not just the add mutation is ran for that specific type that has the webhook.

---

<div class="post-metadata">

**Author:** ![iyinoluwaayoola](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/iyinoluwaayoola/32/4282_2.png) [@iyinoluwaayoola](https://discuss.dgraph.io/u/iyinoluwaayoola)\
**Post date:** [April 26, 2021, 9:09am UTC](https://discuss.dgraph.io/t/add-webhook-on-deep-mutations/13874/4 "2021-04-26T09:09:17Z")

</div>

While this is the current behaviour, I believe it’s much more scalable and useful to trigger separate webhooks per type (in other words, **this is a feature request** ). Given the flexibility of graph queries/mutations, queries can be non-deterministic especially for complex graphs. Using the example you gave, the Author can be created by deeply nesting with Post and vice-versa. In which case, the API implementation must handle webhooks for all possible options—and therefore becoming impractical—for creating either an Author or Post instead of once on the type.

@abhimanyusinghgaur is this something that can be considered as a feature request?

---

<div class="post-metadata">

**Author:** ![iyinoluwaayoola](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/iyinoluwaayoola/32/4282_2.png) [@iyinoluwaayoola](https://discuss.dgraph.io/u/iyinoluwaayoola)\
**Post date:** [May 26, 2021, 12:08am UTC](https://discuss.dgraph.io/t/add-webhook-on-deep-mutations/13874/6 "2021-05-26T00:08:07Z")

</div>

@abhimanyusinghgaur Hope you’re well. I’m now implementing a workaround pending this enhancement. Any ETA at the moment?

---

<div class="post-metadata">

**Author:** ![maaft](https://avatars.discourse-cdn.com/v4/letter/m/4af34b/32.png) [@maaft](https://discuss.dgraph.io/u/maaft)\
**Post date:** [June 10, 2021, 7:01pm UTC](https://discuss.dgraph.io/t/add-webhook-on-deep-mutations/13874/7 "2021-06-10T19:01:39Z")

</div>

+1 for this feature request.

It’s rather odd (and inefficient) that you currently would have to implement a webhook resolver for **every** parent that contains the object of interest as a child.
