What is GraphQL
- A Query language for your application
- A server-side runtime handling the queries
A better way to communicate between client and server GraphQL can be seen as a layer between the client and server that handles queries between them using a certain format. GraphQL does not care how or if the server persists data. The name derives Graph from graph theory and QL stands for query language.
Why GraphQL
With GraphQL you can typically create faster and more flexible APIs giving clients the option to ask for just the data they need.
More flexible data querying:
- Fast, flexible and ease of use.
- Fetch needed data with fewer HTTP requests.
- Less overfetching.
Compared to REST
- Less chatty
- Better Discoverability
- Less over- and underfetching
- Often faster to develop because new req demands less server-side code/changes
- Avoids N+1 fetch workarounds
Mutations are queries that change data. GraphQL queries are more restricted by default than SQL queries. You have to explicitly expose what users can do.
GraphQL doesn't specify what format a server response should use. Could be JSON, XML, YAML etc.