The Power of GraphQL
The Power of GraphQL
The Power of GraphQL
GraphQL
Or How I Learned to Stop
Worrying about REST APIs
Who Am I
Hafiz Ismail
@sogko on all social media
https://wehavefaces.net
What is this about?
What is this about?
Two resources
- Users
- Posts
POST /posts
GET /posts/1
PUT /posts/1
DELETE /posts/1
...
POST /users
GET /users/1
PUT /users/1
DELETE /users/1
...
GET /posts?limit=10
{
"posts": [
{
"id": 1,
"title": "Hello world!",
"author": 10,
"viewCount": 23,
"likedCount": 3,
"likedBy": [1, 3],
},
...
]
}
Great!
Oh wait, we need to get author's
name and avatar URL
Render newsfeed
GET /posts?limit=10
GET /users/10
{
"user": {
"id": 10,
"name": "John Doe",
"nickname": "Johnny",
"age": 23,
"avatar_url": "/avatar/10.jpg"
}
}
GET /posts?limit=10
GET /users/10
GET /users/20
{
"user": {
"id": 20,
"name": "Emily Sue",
"nickname": "M",
"age": 25,
"avatar_url": "/avatar/20.jpg"
}
}