# GraphQL APIs

> Let clients ask for exactly the data they need through a typed schema, resolvers and a single endpoint. Free notes, key concepts, resources and a mini project.

Canonical: https://www.internhack.in/roadmaps/tracks/backend/graphql
Last updated: 2026-11-28

Let clients ask for exactly the data they need through a typed schema, resolvers and a single endpoint.

Intermediate · about 8 hours · difficulty 3/5

Learn first: [Resource-Oriented REST APIs](https://www.internhack.in/roadmaps/tracks/backend/rest-api-design), [ORMs and Query Builders](https://www.internhack.in/roadmaps/tracks/backend/orms-query-builders)

**GraphQL** is a query language and runtime for APIs. Instead of many endpoints, you expose one endpoint and a **typed schema**. Clients send queries describing the exact shape of data they want, and the server returns just that.

### Core concepts

- **Schema** in SDL: types, fields, `Query` (reads), `Mutation` (writes) and `Subscription` (real-time).
- **Resolvers**: functions that fetch each field's data.
- **Introspection**: clients and tools can discover the schema, which powers great developer tooling.

### When it shines

Many client types (web, iOS, Android) with different data needs, deeply related data, and teams that want a strongly typed contract between frontend and backend.

### Costs and pitfalls

- **N+1 in resolvers**: resolving `author` for each of 100 posts triggers 100 queries. Use the **DataLoader** pattern to batch.
- **Expensive queries**: clients can request deeply nested data. Enforce depth and complexity limits and consider persisted queries.
- **Caching** is harder than with REST because everything is a POST to one URL.
- Authorization must be applied per field or per resolver, not only per endpoint.

Popular servers include Apollo Server, GraphQL Yoga, Strawberry (Python) and graphql-java or Spring for GraphQL.

You are ready to move on when you can build a GraphQL API with queries, mutations, DataLoader batching and a query depth limit.

## Key concepts

- **Schema definition language**
- **Queries, mutations, subscriptions**
- **Resolvers**
- **DataLoader batching**
- **Depth and complexity limits**
- **Apollo Server or GraphQL Yoga**
- **Federation**

## Mini project

Build a GraphQL API for a blog (users, posts, comments) and prove with query logs that DataLoader reduces a nested query from 100+ database calls to 3.

## Check yourself

Why is HTTP caching harder with GraphQL than with REST, and what techniques help?

## Free resources

- [Learn GraphQL](https://graphql.org/learn/) (GraphQL Foundation)
- [Apollo Server documentation](https://www.apollographql.com/docs/apollo-server/) (Apollo)

Previous: [API Contracts with OpenAPI](https://www.internhack.in/roadmaps/tracks/backend/openapi-docs) · Next: [gRPC and Protocol Buffers](https://www.internhack.in/roadmaps/tracks/backend/grpc)

## More in Designing and Documenting APIs

- [Resource-Oriented REST APIs](https://www.internhack.in/roadmaps/tracks/backend/rest-api-design)
- [Pagination, Versioning and Rate Limits](https://www.internhack.in/roadmaps/tracks/backend/api-evolution-and-limits)
- [API Contracts with OpenAPI](https://www.internhack.in/roadmaps/tracks/backend/openapi-docs)
- [GraphQL APIs](https://www.internhack.in/roadmaps/tracks/backend/graphql)
- [gRPC and Protocol Buffers](https://www.internhack.in/roadmaps/tracks/backend/grpc)
- [SOAP and Legacy Integrations](https://www.internhack.in/roadmaps/tracks/backend/soap-legacy-apis)

## Related

- [Roadmaps](https://www.internhack.in/roadmaps)
- [Backend Developer Roadmap](https://www.internhack.in/roadmaps/tracks/backend)
