GraphQL: getting started

Lesson 01 · 9 min

Why GraphQL

One endpoint, one request, exactly the fields you need.

9 minLesson 1 of 9Practice includedAsk AI on any point

In REST a profile page often makes three requests (/users/1, /users/1/orders, /users/1/friends) and gets lots of fields it never shows. GraphQL has one entry point, /graphql, and the client describes the shape of the data it needs. The server returns JSON in exactly that shape.

A query and a response of the same shape
AI

You can ask about this rule«GraphQL doesn't replace everything»

  • A response always has data and maybe errors, even with status 200.
  • The schema is a contract: the client sees which fields exist before asking.
  • Popular servers: Apollo Server, GraphQL Yoga, Mercurius.
AI

You can ask about this point«Lesson summary»

Check

Lock it in before you move on

  1. 1. How many endpoints does a GraphQL API usually have?

  2. 2. Who decides which fields are in the response?

  3. 3. An error in one GraphQL field. Which HTTP status is most common?

PracticeSolve the lesson tasksA few short tasks in the editor. Check your code right away and see where it goes wrong.Start practice