Order exactly what you want, nothing more
Day 27 of 149
π Full deep-dive with code examples
The Custom Order
At most restaurants, you order a whole meal:
- Burger + fries + drink + salad
But you maybe just wanted the burger! π
GraphQL lets you order exactly what you need!
REST vs GraphQL
REST (fixed menu):
GET /user/5
Returns: name, email, address, phone, birthday,
avatar, preferences, history, ...
You get everything, even stuff you don't need!
GraphQL (custom order):
{
user(id: 5) {
name
email
}
}
You get exactly: name and email. That's it!
The Magic
One endpoint, infinite flexibility:
{
user(id: 5) {
name
posts {
title
likes
}
friends {
name
}
}
}
Get user + their posts + their friends in ONE request!
When to Use
- REST: Simple CRUD, standard needs
- GraphQL: Complex data needs, mobile apps (save bandwidth)
In One Sentence
GraphQL lets you ask for exactly the data you need in one request, nothing more, nothing less.
π Enjoying these? Follow for daily ELI5 explanations!
Making complex tech concepts simple, one day at a time.
Top comments (0)