GraphQL
What is it?
GraphQL is an API query language that lets clients ask for exactly the data they need in a single request.
Explain like I'm 5
Why was it created?
REST APIs often return too much or too little data, forcing many round-trips. GraphQL was created so clients could request precisely the fields they need.
Where is it used?
- Mobile and web app data fetching
- Aggregating data from multiple services
- Public APIs with diverse clients
- Front-end-driven product teams
Why should developers care?
Many modern apps use GraphQL for flexible data fetching. Front-end and back-end developers both encounter it.
How does it work?
The server defines a typed schema of available data. Clients send a query describing the exact fields they want, and the server returns a matching JSON shape — usually through a single endpoint.
Real-world example
A mobile screen needs a user's name and their last three orders. One GraphQL query fetches exactly that, instead of calling several REST endpoints.
Common use cases
- Precise data fetching for UIs
- Combining many data sources
- Reducing over- and under-fetching
- Strongly typed API contracts
Advantages
- Clients fetch exactly what they need
- Single request for related data
- Strongly typed schema
- Self-documenting via introspection
Disadvantages
- More complex server setup
- Caching is harder than REST
- Easy to write expensive queries
- Overkill for simple APIs
When should you use it?
When clients have varied data needs or you must combine multiple sources.
When should you avoid it?
For simple resource APIs where REST is easier to cache and operate.
Alternatives
Related terms
Interview questions
Beginner
- What problem does GraphQL solve?
- How does a GraphQL query differ from a REST call?
Intermediate
- What is a resolver?
- What is the N+1 query problem in GraphQL?
Senior
- How do you prevent abusive or overly deep queries?
- How would you handle caching and persisted queries?
Common misconceptions
- "GraphQL replaces databases" — no, it's an API layer that calls your existing data sources.
- "GraphQL is always better than REST" — it adds complexity that simple APIs don't need.
Fun facts
- It was developed internally at Facebook before being open-sourced.
- Most GraphQL APIs expose a single endpoint rather than many URLs.
Timeline
- 2015 — Publicly released by Facebook
Learning resources
Quick summary
GraphQL lets clients request exactly the data they need in one typed query, reducing over- and under-fetching.
Cheat sheet
- Query language for APIs
- Ask for exact fields
- Typed schema, single endpoint
- Great for varied client needs