liveBook · Manning

GraphQL

As explained in Contract Testing in Action

GraphQL is a query language and runtime for APIs that lets clients request structured data through a typed schema.

GraphQL is an API standard and query language that lets consumers request or update specific data through a typed schema. Unlike REST endpoints with fixed response structures, a GraphQL query describes the desired response shape, allowing one endpoint to serve multiple purposes. section 3.8.1 section 7.1

A GraphQL application separates the contract from the data-fetching behavior:

  • The GraphQL schema definition language (SDL) declares the fields and types consumers may query. section 7.1
  • Resolvers define how the API obtains each requested value, such as retrieving a movie by identifier. section 7.1
  • Queries that request fields absent from the SDL fail, making the schema an explicit consumer contract. section 7.1

Movie landing page

A movie landing page may need the movie, its actors, and other movies featuring those actors. REST may require several GET requests and return unused data; GraphQL can retrieve the requested structure with one query. Apollo Server can expose the GraphQL layer, while Apollo Client consumes it from a JavaScript frontend. section 7.1 section 7.2

Figure 7.2 A web consumer making a single query to a GraphQL endpoint to retrieve all the data they require
figure

Shows a web consumer making one GraphQL query to retrieve the data it needs, contrasting with multiple REST requests. section 7.1

How Contract Testing in Action covers it

How deep it goes
Explains response shaping, SDL, resolvers, and Apollo integration, but defers broader frontend and backend integration details.
Examples
Uses a movie landing page, Movie SDL type, movie resolver, Apollo application, and single-query versus multi-request comparison.
What it assumes
Assumes familiarity with APIs and REST while defining schemas, resolvers, consumers, and providers through a movie example.
What you can do after
Apply GraphQL through Apollo tools and evaluate consumer data needs, invalid queries, output changes, and response status behavior.
How it connects
Connects GraphQL with REST, contract testing, schemas, resolvers, Apollo, gRPC, and SOAP.

Also explained in

Compare how 6 books explain GraphQL →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Contract Testing in Action. The section links point to the parts of the book it draws on.