Generally a query is when you fetch data and mutation is when you manipulate data. But how would I implement a mutation without any arguments?
In my particular case I have delete and create 2fa token endpoints. Both the delete and create token have no arguments as they rely on the logged in user id. They both either destroy or create a record in the database. So I would prefer that they be mutations. But that is not possible?
I'm using Graphql-Ruby. But this is more of a general Graphql question.
EDIT:
So turns out I was wrong. I couldn't find any info about it so I just assumed it wasn't possible. I hope this helps someone else. In Graphql-Ruby you can do:
mutation {
createFoo(input: {})
}
A Mutation is a GraphQL Operation that allows you to insert new data or modify the existing data on the server-side. You can think of GraphQL Mutations as the equivalent of POST , PUT , PATCH and DELETE requests in REST. The above mutation inserts a new todo note into the database.
In a GraphQL API, queries are used to fetch data from a server, while mutations are used to modify or write server-side data. Therefore, it is essential to understand its structure when defining a mutation, including the type definition, the mutation name, and variable definitions.
Update mutations take filter as an input to select specific objects. You can specify set and remove operations on fields belonging to the filtered objects. It returns the state of the objects after updating. Note Executing an empty remove {} or an empty set{} doesn't have any effect on the update mutation.
If a mutation doesn't declare any parameters than it must looks this way:
mutation {
createFoo : Payload
}
So you just must not to write parentheses at all.
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