GraphQL

A query language for APIs letting clients request exactly the data they need.

CurrentintermediateGuide only -- no course yet

Overview

GraphQL lets a client specify the exact shape of data it wants in a single request, rather than hitting multiple fixed REST endpoints and over- or under-fetching data. It trades REST's simplicity for more precise client-driven queries, at the cost of additional server-side complexity.

What it is
A query language and runtime for APIs where clients describe exactly what data they need.
Why it's used
To avoid over-fetching (getting more fields than needed) or under-fetching (needing multiple round trips) common with fixed REST endpoints.
Where it fits
An alternative to REST for APIs with complex, nested, client-varying data needs.

Core concepts

  • Schema and types
  • Queries and mutations
  • Resolvers
  • A single endpoint vs. many REST routes

Example

The client specifies exactly which fields it wants (title, author.name) -- the server returns precisely that shape, nothing more.

query {
  book(id: 42) {
    title
    author { name }
  }
}

Common use cases

  • APIs with complex, nested data requirements
  • Mobile apps that need to minimize network round trips

Project ideas

  • Design a GraphQL schema (on paper) for the same to-do app used in the REST project idea, and compare the two approaches

Official references