GraphQL is a query language for APIs that gives clients precise control over data retrieval. Unlike REST, a single GraphQL endpoint handles all operations.
Schema definition: define types, queries, and mutations in SDL (Schema Definition Language). type User { id: ID!, name: String!, email: String! }.
Resolvers implement schema fields: Query: { users: () => db.getUsers() }. Support arguments, pagination, and relationships. N+1 problem solved with DataLoader batching.
Apollo Server integrates with Express. Apollo Client (React) provides caching, optimistic updates, and type-safe queries.
When to choose GraphQL: multiple related resources in one request, mobile apps needing bandwidth efficiency, rapidly evolving APIs. When to choose REST: simple CRUD, file-heavy operations, HTTP caching.
Subscriptions provide real-time updates via WebSockets. Error handling follows a standard format with extensions for debugging.