What is difference between Mutation and Query ?
What is difference between Mutation and Query ?
The difference between a Mutation and a Query in GraphQL lies primarily in their purpose and execution behavior.
Query: A Query is used to fetch data from the server. It is analogous to a GET request in REST APIs. Queries are read-only operations and do not modify the server's state. They are used when you need to retrieve specific data from the server without making any changes to it.
Mutation: A Mutation is used to modify data on the server. This includes creating, updating, or deleting data. Mutations are analogous to POST, PUT, PATCH, and DELETE requests in REST APIs. They are used when you need to change the state of the server or persist new data.
Query: The syntax for a query typically starts with the query keyword, although this keyword is optional. Queries specify the fields to be fetched and can include arguments to filter or customize the data retrieval.
query {
user(id: "1") {
name
email
}
}
This query fetches the name and email of a user with a specific id.
Mutation: The syntax for a mutation starts with the mutation keyword. Mutations specify the operation to be performed and the data to be modified. They often include arguments to specify the data to be changed.
Đăng nhập để tham gia thảo luận cùng mọi người.
Chưa có bình luận nào
Hãy là người đầu tiên chia sẻ suy nghĩ của bạn.