It was chosen because it worked
The GraphQL API has a strongly typed schema
GraphQL Schema is a convention that specifies the functionality of the API.
- A strict Scheme defines the operations supported by the API (Query, mutation, subscribe)
- The API documentation is automatically generated based on the corresponding schema, making setting up the back-end API very simple
On-demand access and strong scalability
This is actually pretty straightforward, because we write a query in front of it, and that’s the query that determines the data that we need
This solves two typical problems with traditional REST apis: Overfetching and Underfetching
You don’t have to rely on fixed data structures returned by the REST side.
For the fixed data structures returned by the older data query apis, we even have to do extra processing on the front end
Overfetching
I return more data than I need
- The old API
- You have a fixed background that takes in certain parameters and decides what database data to return based on those parameters
- GraphQL
- Write the data I need directly in the front end request query so that I don’t send too much data back
Underfetching
I return less data than I need
- The old API
- I’ll probably have to ask for an excuse to get the data I need
- In particular, data like some connections
- For example, the user’s data is first obtained, and then the user’s article data needs to be obtained in the background once for each user request
- That’s obviously multiple requests
- GraphQL
- All in one request
Support rapid product development
There are many front-end frameworks that support GraphQL (Apollo, Relay, etc.)
There are even tools like GraphQl Faker that make it possible to design all the schemas before coding
Composing GraphQL API
The joining together of API
You can freely concatenate multiple apis
And you can do nested queries
There is a rich community
Several frameworks, such as Express, have corresponding middleware
The number of debugging tools will also increase
I can stop writing SQL Server code
That could be an advantage, too
reference
www.jianshu.com/p/03a7d3903…