Query vs Mutation
In tools like React Query, Apollo, and GraphQL, data operations are generally split into two categories:
- Query: Used for fetching or reading data from the server. Queries are generally idempotent (they don’t change the server state). Examples include
GETrequests, fetching a list of users, etc. In React Query, you handle this with theuseQueryhook. - Mutation: Used for modifying data on the server (creating, updating, or deleting). Examples include
POST,PUT,PATCH, andDELETErequests. In React Query, you handle this with theuseMutationhook.