
mutation CreateMovie ($title: String!, $launched: Date!) {
createMovie (title: $title, launched: $launched){
id
title
launched
}
}
[submitted data]
{
“title”: “Seven Samurai”
“launched”: “1950”
}
All queries, together with mutation queries, can return knowledge. Right here, the checklist of fields within the curly braces after createMovie
specifies what we wish to see returned from the server after a brand new file is created with this request. The worth for the id
discipline, on this case, could be created by the database; the values for the opposite fields are submitted within the question.
One other factor to bear in mind is that the queries and knowledge sorts used to return knowledge are by design totally different from these used to request knowledge. Mutation queries must validate incoming knowledge, so the kinds used for these queries are supposed to serve that perform. Likewise, the fields utilized in returned question objects are for show, not validation. When you soak up a GraphQL object as returned from a question, it might need fields with round references or different points that make it unusable as a question parameter.
Why use GraphQL?
A key cause to select GraphQL over REST is the express, declarative nature of GraphQL queries. Having a proper definition for the way queries and returned knowledge ought to look has benefits other than being constant throughout APIs and implementations.