If you have built web apps, you have almost certainly consumed a REST API: you hit /users/42, get back a JSON blob, and move on. REST has served the web well for two decades, so why did Facebook invent GraphQL in 2012 and open-source it in 2015? The short answer: modern apps ask for data in ways REST was never designed to handle gracefully. In this lesson we will look at the real pain points GraphQL solves, see our first query, and set expectations for the rest of this course.
REST models your API as a set of resources, each living at its own URL. That is elegant until your UI needs data that spans several resources at once. Three problems show up again and again:
/users/42 returns forty fields when your screen needs three. On mobile networks, that wasted payload is real money and real latency./users/42/profile-page-v2 style endpoints. Soon you have dozens of bespoke endpoints nobody dares delete.GraphQL is a query language for your API plus a server-side runtime for executing those queries against a type system you define. Instead of many endpoints, you expose one endpoint, and the client sends a query describing exactly the shape of data it wants:
query {
user(id: "42") {
name
email
posts(last: 5) {
title
likeCount
}
}
}The response mirrors the query, no more and no less:
{
"data": {
"user": {
"name": "Ada Lovelace",
"email": "ada@example.com",
"posts": [{ "title": "On Engines", "likeCount": 128 }]
}
}
}One request, exactly the fields the screen needs, nested relationships resolved server-side. That is the core promise.
Every GraphQL API is backed by a schema: a strongly typed description of every object, field, and operation the server supports. Tools can introspect this schema, which gives you autocomplete in editors, automatic documentation, and client-side type generation for free. Compare that with REST, where the contract usually lives in a Swagger file that may or may not match reality.
GraphQL is not a silver bullet. REST remains a great fit when:
GraphQL shines when many different clients (web, iOS, Android, partners) consume the same data with different shapes, and when your data is a graph of related entities.
Across twelve lessons you will learn schemas and types, queries, arguments, mutations, and resolvers; build a working GraphQL server in Node.js; consume it from a frontend; and finish with advanced topics like pagination, error handling, the N+1 problem, and production best practices.
Next up: Schemas and Types, where we define the contract that makes all of this possible.