GraphQL (GQL) Mutations
Author:
Fluent Commerce
Changed on:
5 Apr 2024
Overview
Mutations in GraphQL are operations designed to modify server-side data, encompassing the creation, updating, or deletion of records. They play a critical role in dynamic data management within GraphQL applications, allowing for precise and controlled data manipulation.
Key points
- Mutations in GraphQL are used for creating, updating, or deleting data, and are crucial for any operation that changes server-side information.
- Create mutations always generate data with a "CREATED" status, which can trigger orchestration events for workflow processes.
- Update mutations require mandatory parameters to uniquely identify and modify existing data entries.
Mutations
A GraphQL mutation is a type of operation used to modify data on the server. While queries are used to fetch data, mutations are used to create, update, or delete data.
Mutation Operations
Mutation operations are used for creating or updating data. All mutation operations take a single parameter and have the naming convention:
`<<mutationName>>(<<MutationNameInput>>):<<Type>>`
Examples:
`createOrder(CreateOrderInput): Order // Create Order mutation`
`updateOrder(UpdateOrderInput): Order // Update Order mutation`
Create
Create mutations are used to create new data.
- Every create mutation creates the data in the “CREATED” status. This enables the clients to trigger orchestrations for that object. If the client wishes to change the status of any object after creation, Fluent recommends using the update mutation to do so. This could be particularly helpful when a client creates objects of types that cannot be orchestrated. For example, Customer.
- All objects of orchestrate-able types fire orchestration events on creation. This can be used to trigger workflows.
Update
Update mutations are used for updating existing data.
- Input types for update mutations have mandatory parameters that are used to identify the object to be updated uniquely.