Flexible Queries with GraphQL

This chapter explores under-fetching and over-fetching in REST APIs, and how GraphQL solves them. It is framed around a headless commerce API, with a website and a phone app as clients.

After reading this chapter, you should be able to:

  • Define over-fetching and under-fetching, and explain why they hurt a phone app more than a website
  • Describe how a REST API can reduce over-fetching and under-fetching, and what each approach costs
  • Explain what problem GraphQL was built to solve and how it solves it
  • Read a GraphQL query and say what shape its response has
  • List the decisions a designer makes for a GraphQL API
  • Read a GraphQL schema: its types, fields, nullability, and entry points

Sections

  1. Selling Online
  2. The Shop API
  3. The REST Version of the Shop API
  4. Building the Cart Page
  5. Solving Under-Fetching and Over-Fetching
  6. A Query Language for the API
  7. Designing a GraphQL API
  8. The Schema
  9. Queries