GraphQL
Table of Contents
From What Is GraphQL? REST vs. GraphQL [ByteByteGo] : GraphQL is a query language for API developed by Meta.
1. Advantages
- It provides a schema of the data in the API and gives clients the power to ask for exactly what they need.
- It could aggregate multiple resource requests into a single query. (No N+1 queries problem)
- It also supports mutations, and subscriptions.
2. Similarity And Differences with REST
- REST and GraphQL both use HTTP.
- Both make a request via a URL, and both can return a JSON response in the same shape.
- GraphQL doesn’t use URLs to specify the resources that are available in the API. Instead, it uses a GraphQL schema. We can send a complex query that fetches additional data according to relationships defined in the schema. Doing the same in REST is more complicated. We would have to do that client side with multiple requests. This is a common problem resulting in N+1 queries.