Introduction to GraphQL
GraphQL advertises itself as a query language for APIs. To understand what this means, let’s compare it with REST.
In REST, we usually have endpoints that give us information about a resource, for example: GET /user/1
could return something like:
1
2
3
4
5
{
"id": 1,
"name": "Jose",
"phone": "999-888-7777"
}
We have multiple endpoints we can use to get different information about different resources. If we need an endpoint that contains information from different resources, we sometimes create endpoints for specific purposes: GET /user/1?includeParents=true
. Which could return something like this:
1
2
3
4
5
6
7
8
9
{
"id": 1,
"name": "Jose",
"phone": "999-888-7777"
"parents": {
"mom": "Maria",
"dad": "Carlos"
}
}