I have several GraphQL queries and mutations, now I'm trying to implement a delete mutation without returning any data:
type Mutation{ addElement(element: ElementData): ID removeElement(id: ID): ¿? }
However, it seems to be required to have a return value for the delete operation. Is there a way to perform an "empty" response in GraphQL? I would like to avoid things like returning a boolean or status flag if possible.
I'm not sure on what are the best practices for GraphQL delete operations.
In this chapter, we will learn mutation queries in GraphQL. Mutation queries modify data in the data store and returns a value. It can be used to insert, update, or delete data.
Mutations allow you to modify server-side data, and it also returns an object based on the operation performed. It can be used to insert, update, or delete data. Dgraph automatically generates GraphQL mutations for each type that you define in your schema.
In other words, if you return an empty object ( {} ), an empty array ( [] ) or some other value, GraphQL will treat this as you returning an object and not a null value!
Learn how to define nullable and non-nullable fields your GraphQL schema with the schema-first approach. The GraphQL type system has built-in support for null, and non-null fields. GraphQL is null by default. If you've worked with GraphQL before this probably looks very familiar.
According to this Github issue you cannot return nothing.
You can define a return type which is nullable e.g.
type Mutation { addElement(element: ElementData): ID removeElement(id: ID): Boolean }
But I suggest you return the id of the deleted element, because if you want to work with a cached store you have to update the store when the delete mutation has ran successfully.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With