<img height="1" width="1" style="display:none" src="https://www.facebook.com/tr?id=1063935717132479&amp;ev=PageView&amp;noscript=1 https://www.facebook.com/tr?id=1063935717132479&amp;ev=PageView&amp;noscript=1 "> Learn GraphQL 101

Learn GraphQL 101

Before you begin

If you find bugs in this training or have suggestions, create an issue or email contact@bitovi.com.

Overview

GraphQL is a query language for APIs, plus a server runtime that answers those queries using functions you write.

In this course you’ll work with a small API for a fictional insurance company, with policies and policyholders, built with Apollo Server. You’ll query it, find its limits, and then extend it yourself.

After this course, you’ll be able to:

  • Explain two of GraphQL’s three operation types, queries and mutations (subscriptions come in GraphQL 102)
  • Explain how a schema and its resolvers relate
  • Write queries and mutations, with arguments, nested fields, variables, directives, and fragments, against a GraphQL API
  • Send a query from code, the way an app does
  • Explore an unfamiliar API’s schema with introspection
  • Extend an API by adding schema fields and arguments, and the resolvers that implement them
  • Change a schema without breaking clients, using @oneOf and @deprecated
  • Describe GraphQL’s trade-offs versus REST, including caching and the N+1 problem

Prerequisites

This course is for frontend and backend developers who are new to GraphQL. You don’t need to know GraphQL or Apollo Server before you start.

You’ll edit the API’s server code, so you should be comfortable reading and writing JavaScript, including arrow functions, array methods like filter and map, spread syntax (...), and async functions. The API is written in TypeScript. You don’t need to know TypeScript: the course explains the few types you’ll see.

You’ll also need:

  • A GitHub account. The exercises run in a GitHub Codespace, a development environment in your browser, so you don’t install anything. Personal accounts include a free monthly amount of Codespaces use.
  • Basic terminal use. You’ll run commands like npm run dev and curl.

Outline

  1. Course Setup: create the course Codespace and start the API
  2. What is GraphQL?: how GraphQL compares to REST, and your first query
  3. The Course Data: the policyholders and policies the API starts with
  4. Writing Queries: nested fields, arguments, variables, directives, fragments, sending a query from code, and request validation
  5. Exploring the Schema: ask the API to describe its own schema with introspection
  6. Schemas and Resolvers: how the server answers queries, and adding a new argument
  7. Mutations: issue policies with input types, make a field required, and evolve the schema with @oneOf and @deprecated
  8. N+1 and DataLoader: why nested fields can multiply the work your server does, and batching with DataLoader
  9. Final Exam: add insurance claims to the API, using everything from the course