08 June, 2019
GraphQL is Facebook’s attempt at addressing the shortcomings of RESTful APIs.
Its' a strongly typed query language for our API (like Typescript for your API) that makes it easier to declaratively fetch and mutate data without having to worry about backend implementation details. Unlike a classic REST architecture, it lets clients fetch lots of related data in a single request.
The core difference between GraphQL and REST can be boiled down as follows:
REST has a set of endpoints that each return fixed data structures GraphQL has a single endpoint that returns flexible data structures. Request details are in the POST body (Can do GET request for queries).
This works because with GraphQL the client can dictate the shape of the response. It submits a query to the server that precisely describes its data needs. The server resolvesthat query and returns only the data the client asked for.
In REST the shape of the response is determined by server. In GraphQL it is:
Terminology
Animal {
__resolverType(animal, ctx, info). // theres no args on interfaces
}