GraphQL: Ask for What You Need
Facebook's query language for APIs solved the over-fetching problem and gave clients control over the shape of their data.
The Mobile Problem
By 2012, Facebook’s mobile app was slow. The REST API returned full user objects when the app only needed a name and avatar. Each screen required multiple round-trips. The news feed alone hit dozens of endpoints.
Lee Byron, Dan Schafer, and Nick Schrock built GraphQL to solve this: a query language where the client specifies exactly what data it needs, and the server returns exactly that — no more, no less.
query {
user(id: "123") {
name
avatar
posts(first: 5) {
title
likeCount
}
}
}
The Trade-offs
GraphQL eliminated over-fetching and under-fetching, but introduced new complexities: N+1 query problems on the server, cache invalidation challenges (no URL-based caching like REST), and the need for schema governance as the graph grows. It’s a powerful tool — but not a universal replacement for REST.