Back to results for “Error Handling”
Flutter › GraphQL in Flutter

What is a GraphQL mutation, and how does it genuinely differ from a regular query specifically in terms of properly performing an action that actually genuinely changes data on the server?

Intermediate

Answer

While a GraphQL query is specifically used purely for reading and retrieving genuinely existing data without ever actually causing any kind of side effect, a mutation is specifically used whenever you genuinely need to actually create, update, or delete data on the server, and much like a query, a mutation also lets you precisely specify exactly which specific resulting fields you genuinely want returned back once that particular action has actually genuinely completed, such as receiving back a newly created order's own specific generated identifier immediately after successfully placing that order.
mutation {
  createOrder(input: { productId: "123", quantity: 2 }) {
    id
    status
  }
}
Real-world example A checkout screen executes a createOrder mutation, properly submitting the customer's genuine specific order details while also conveniently receiving back that newly created order's own generated identifier and its current status all together within that exact same single request.

Common follow-ups: How do you actually properly execute a mutation from within Flutter using the graphql_flutter package's own dedicated Mutation widget?;What genuinely happens if a mutation actually fails partway through on the server?