Mutations
Problem
You want to update or change data in your GraphQL Server from the Client applications.
Solution
You can use Mutation type in GraphQL to edit or update data in your server. Only the types or fields that are defined in the mutation root type are allowed to be editable or changed. The value that is returned from the mutation fields represents the changed state of the entity from the server.
For example, if you want to add a new post, you can define the mutation type with the addPost method as shown below.
type Mutation { addPost(input: AddPostInput!): AddPostPayload! }
Your client can call this mutation as shown below to add a new post
mutation { addBook(input: { title: "Welcome to DeveloperPublish.com", author : "Senthil Kumar Balu" }) { post { id title author } } }
Naming Conventions
It is recommended to have a single argument for your mutations with the name suffixed with input. You may also have to return a payload object for each mutation that you wish to change the data.