Skip to the workspace
Pebellslearn by building
Introduction to GraphQL  ›  Lesson

What is GraphQL

What is GraphQL 12 minGraphQL is a query language for APIs in which the client describes the shape of the data it wants and the server returns JSON in exactly that shape, guided by a typed schema.

graphql / What is GraphQL

Explore each scene at your own pace.

01 · The rule

The rule

What is GraphQL

A bookshop app needs a book's title, its author's name and its three newest review ratings, and nothing else. With GraphQL the app writes that wish down as a query, sends it to the server, and gets back JSON in exactly that shape. This whole course works on that one bookshop API.

The rule

Describe the shape you want; the server fills it in.

GraphQL is a query language for APIs plus a set of rules a server follows to answer it. It has three parts that always travel together:

  • A schema: the server's typed menu of everything a client may ask for.
  • Operations: a query to read, a mutation to change, a subscription to listen.
  • Resolvers: server functions that fetch the value for each field.

Here is part of the bookshop schema, written in GraphQL's schema language:

type Query {
  book(id: ID!): Book
}

type Book {
  id: ID!
  title: String!
  price: Float!
  author: Author!
}

type Author {
  id: ID!
  name: String!
}

A client asks for a book and picks its fields:

query {
  book(id: "b1") {
    title
    author { name }
  }
}

The answer mirrors the question:

{ "data": { "book": { "title": "The Salt Road", "author": { "name": "Mira Kapoor" } } } }

GraphQL began inside Facebook in 2012, was published as an open specification in 2015, and is now looked after by the GraphQL Foundation. It is a specification, not a product: many servers in many languages implement it. It also says nothing about which database you use. Your data can live in PostgreSQL, another service or a file; resolvers hide that.

Scene 1 of 5
Hover to wake the cannons. Drag to move, or use arrow keys when focused. Press Enter to fire a shot.