Learn the fundamental distinction between queries (read operations) and mutations (write operations) in GraphQL.
In GraphQL, all operations are categorized as either a 'query' or a 'mutation'. This distinction is fundamental to understanding how to interact with a GraphQL API and represents a clear separation of concerns between read and write operations. A Query is a read-only operation. It is used to fetch data from the server. When you send a query to a GraphQL server, you are asking for specific fields on objects. The structure of your query mirrors the shape of the JSON data you will get back. Queries allow the client to specify exactly the data it needs, which solves the over-fetching and under-fetching problems common in REST APIs. For example, a client could request just the `name` and `email` of a user, without getting their entire address history. A Mutation is an operation that modifies data on the server. If you want to create, update, or delete data, you must use a mutation. The syntax for a mutation is very similar to a query, but you must use the `mutation` keyword at the beginning of your operation. Just like queries, mutations can also return data. After a mutation modifies data, it can be useful to fetch the new state of the modified object. For instance, after a mutation to update a user's name, you can ask for the user's `id` and new `name` back in the same operation. This clear separation is a design principle: any operation that causes a write should be sent explicitly via a mutation.