# Why does custom dql not support mutation?

**URL:** <https://discuss.dgraph.io/t/why-does-custom-dql-not-support-mutation/10366>\
**Category:** GraphQL\
**Tags:** discussion, kind:question, kind:enhancement, status:accepted, ticket:created\
**Created:** [September 15, 2020, 7:53am UTC](https://discuss.dgraph.io/t/why-does-custom-dql-not-support-mutation/10366 "2020-09-15T07:53:10Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![asuka](https://avatars.discourse-cdn.com/v4/letter/a/dec6dc/32.png) [@asuka](https://discuss.dgraph.io/u/asuka)\
**Post date:** [September 15, 2020, 7:53am UTC](https://discuss.dgraph.io/t/why-does-custom-dql-not-support-mutation/10366/1 "2020-09-15T07:53:10Z")

</div>

I want to delete through custom dql:

```auto
type Mutation {
    deleteEntityById(id: String!): Entity @custom(dql: """
      upsert {
        query q($id: string) {
          E as var(func: type(Entity)) @filter(eq(Entity.id, $id)) {
            U as Entity.urls
            M as Entity.medias
          }
        }    
        mutation {
          delete {
            uid(E) * * .
            uid(U) * * .
            uid(M) * * .
          }
        }
      }
    """)
}

```

But when I update the schema, I receive an error message:

```auto
@custom directive with `dql` can be used only on queries

```

I hope custom dql can support all dql features, not limited to query.

---

<div class="post-metadata">

**Author:** ![chewxy](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/chewxy/32/4339_2.png) [@chewxy](https://discuss.dgraph.io/u/chewxy)\
**Post date:** [September 15, 2020, 10:42am UTC](https://discuss.dgraph.io/t/why-does-custom-dql-not-support-mutation/10366/2 "2020-09-15T10:42:01Z")

</div>

I suspect that allowing mutations via `@custom` would cause a lot of headaches - your graphql code will no longer be deterministic.

But I think @pawan might be the best person to answer this and perhaps offer some discussions around it.

---

<div class="post-metadata">

**Author:** ![asuka](https://avatars.discourse-cdn.com/v4/letter/a/dec6dc/32.png) [@asuka](https://discuss.dgraph.io/u/asuka)\
**Post date:** [September 15, 2020, 4:19pm UTC](https://discuss.dgraph.io/t/why-does-custom-dql-not-support-mutation/10366/3 "2020-09-15T16:19:19Z")

</div>

The dql has many features that the GraphQL API cannot do. If custom dql does not support mutation, it will bring a lot of difficulties and even have to give up the GraphQL API.

---

<div class="post-metadata">

**Author:** ![ahsan](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/ahsan/32/3517_2.png) [@ahsan](https://discuss.dgraph.io/u/ahsan)\
**Post date:** [September 15, 2020, 4:28pm UTC](https://discuss.dgraph.io/t/why-does-custom-dql-not-support-mutation/10366/4 "2020-09-15T16:28:07Z")

</div>

Can you please explain your use case, may be there is some other way to achieve that?

---

<div class="post-metadata">

**Author:** ![pawan](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/pawan/32/1946_2.png) [@pawan](https://discuss.dgraph.io/u/pawan)\
**Post date:** [September 15, 2020, 4:40pm UTC](https://discuss.dgraph.io/t/why-does-custom-dql-not-support-mutation/10366/5 "2020-09-15T16:40:22Z")

</div>

The initial aim for adding custom DQL was just to give you the ability to perform complex DQL queries like aggregations, multiple var blocks and such. We didn’t support custom DQL mutations for the sake of simplification but we can definitely do that.

Infact, you could right now define a GraphQL query which ultimately does a DQL upsert and that would work. We will be looking into supporting this as well.

---

<div class="post-metadata">

**Author:** ![minhaj](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/minhaj/32/3468_2.png) [@minhaj](https://discuss.dgraph.io/u/minhaj)\
**Post date:** [March 22, 2021, 1:12pm UTC](https://discuss.dgraph.io/t/why-does-custom-dql-not-support-mutation/10366/9 "2021-03-22T13:12:39Z")

</div>

We are not going to support custom DQL mutations. The best way to achieve this is through [lambdas](https://dgraph.io/docs/graphql/lambda/mutation/).  
cc: @abhimanyusinghgaur

---

<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:** [March 22, 2021, 2:02pm UTC](https://discuss.dgraph.io/t/why-does-custom-dql-not-support-mutation/10366/10 "2021-03-22T14:02:53Z")

</div>

@minhaj Could you guys add **JSON Mutation Format** support to lambdas?

> [@Slash DGraph Lambdas Feature Requests / Small Change](http://discuss.hypermode.com/t/slash-dgraph-lambdas-feature-requests-small-change/13288/1):
>
> This is probably the easiest fix. Allow **DQL** within lambdas to accept JSON Mutation Format. You could easily [update the code here](https://github.com/dgraph-io/dgraph-lambda/blob/8bb34dd627d0522fe8c0516cf784a5ecadc89523/src/dgraph.ts#L39).
> 
> My suggestion would be something as simple as:
> 
> ```auto
> "Content-Type": typeof obj == 'object' ? "application/json" : "application/rdf"
> 
> ```
> 
> It may be a little more complicated than that, but you get the drift.

There are many use cases for this.

Thanks,  
J

---

<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:** [March 23, 2021, 6:55am UTC](https://discuss.dgraph.io/t/why-does-custom-dql-not-support-mutation/10366/11 "2021-03-23T06:55:07Z")

</div>

> [@jdgamble555](#):
>
> Could you guys add **JSON Mutation Format** support to lambdas?

Yes, we will get this done for the 21.03 release.

---

<div class="post-metadata">

**Author:** ![MIguel\_Angel\_Esteve](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/miguel_angel_esteve/32/6563_2.png) [@MIguel\_Angel\_Esteve](https://discuss.dgraph.io/u/MIguel_Angel_Esteve)\
**Post date:** [May 3, 2021, 8:48am UTC](https://discuss.dgraph.io/t/why-does-custom-dql-not-support-mutation/10366/12 "2021-05-03T08:48:12Z")

</div>

Hi, I also have a similar use case. I find it very strange and not very homogeneous to have this option for queries and not for mutations. Are you planning to add this option in the future?

Regards!

---

<div class="post-metadata">

**Author:** ![BenW](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/benw/32/7532_2.png) [@BenW](https://discuss.dgraph.io/u/BenW)\
**Post date:** [November 13, 2021, 6:31am UTC](https://discuss.dgraph.io/t/why-does-custom-dql-not-support-mutation/10366/14 "2021-11-13T06:31:29Z")

</div>

> [@pawan](#):
>
> The initial aim for adding custom DQL was just to give you the ability to perform complex DQL queries like aggregations, multiple var blocks and such. We didn’t support custom DQL mutations for the sake of simplification but we can definitely do that.
> 
> Infact, you could right now define a GraphQL query which ultimately does a DQL upsert and that would work. We will be looking into supporting this as well.

+1 for custom DQL mutations.

> [@minhaj](#):
>
> We are not going to support custom DQL mutations. The best way to achieve this is through [lambdas](https://dgraph.io/docs/graphql/lambda/mutation/).

Why have you decided not to support custom DQL mutations? Would really appreciate an explanation here. Makes sense to me to have as much of my API, ideally all of it, defined in one place—rather than have backend logic spread across the schema as well as lambda functions.
