⬡ GraphQL Beginner

What is the difference between query, mutation, and subscription operations?

Answer

Query: a read-only operation that fetches data without causing side effects. Resolvers are called in parallel. Used for GET-like operations — reading user profiles, lists, search results. Mutation: a write operation that modifies server-side data. Top-level mutation fields execute serially. Used for creating, updating, or deleting data — login, creating a post, purchasing an item. Subscription: a long-lived operation that establishes a connection (typically WebSocket) and receives server-pushed events when data changes. Used for real-time features — chat messages, live notifications, dashboard updates. All three are defined in the root types type Query, type Mutation, type Subscription. If the operation keyword is omitted, GraphQL assumes it's a Query (shorthand). Best practice: always include the operation keyword for clarity.