Why does custom dql not support mutation?

I want to delete through custom dql:

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:

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

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

1 Like

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.

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.

1 Like

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

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.

We are not going to support custom DQL mutations. The best way to achieve this is through lambdas.
cc: @abhimanyusinghgaur

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

There are many use cases for this.

Thanks,
J

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

1 Like

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!

1 Like

+1 for custom DQL mutations.

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.

1 Like