GraphQL
GraphQL is an API style where the client can request exactly the fields it needs.
Instead of multiple endpoints (/users, /users/:id, /users/:id/posts), GraphQL often exposes a single endpoint (commonly /graphql) and the client sends queries.
Where GraphQL Is Used
Section titled “Where GraphQL Is Used”- Frontends that need flexible queries (complex pages, many UI components)
- Public APIs where clients need different shapes of the same data
Industry Examples (Companies)
Section titled “Industry Examples (Companies)”- GitHub: GraphQL API for developer/platform integrations
- Shopify: GraphQL Admin API
- Meta (Facebook): created GraphQL and uses it heavily
Pros / Cons
Section titled “Pros / Cons”Pros:
- Reduces over-fetching/under-fetching (client chooses fields)
- Strong typing via schema
- Great developer experience with tooling
Cons:
- Caching can be harder than REST (queries vary)
- You still need to design your schema carefully
- Performance pitfalls (e.g., N+1 queries) if resolvers are naive
Tiny Example
Section titled “Tiny Example”Query:
query { user(id: 42) { id name posts { id title } }}Response:
{ "data": { "user": { "id": 42, "name": "Alice", "posts": [{ "id": 1, "title": "Hello" }] } }}