Odyssey

Voyage III: Federation in Production

Airlock in productionVariants in a supergraphPublishing to a graph variantSchema checks in a supergraphLocal schema checksSchema checks in CIPublishing & deploymentBuild check errorsOperation check errorsObservability with GraphOS Studio
4. Schema checks in a supergraph
4m

Overview

The Listings team has some exciting updates ready to publish to the registry, but they need to be confident in these schema changes before publishing them to the production variant. Fortunately, there's an GraphOS feature to help with that: schema checks!

In this lesson, we will:

  • Learn about the different types of schema checks
  • Understand how schema checks fit into the overall process of updating a supergraph
  • Learn about the launch process in GraphOS

In this lesson, we'll focus mainly on the high-level overview of the process. The next lesson will dive more into the details of how to run each check.

What are schema checks?

Schema checks are a set of predefined tests that help identify potential failures caused by schema updates. They check for issues like incompatibilities between subgraph schemas or breaking existing client operations. With schema checks, we can ensure that our schema changes won't cause issues when we deploy to production.

There are three types of schema checks: build checks, operation checks and linter checks.

Build checks

Build checks validate that a subgraph's schema changes can still compose successfully with other subgraph schemas in the supergraph.

Illustration of subgraph characters being checked for composition

For example, if a new type is added to one subgraph, a build check determines whether that addition is compatible with the rest of the subgraphs in the supergraph. If it isn't, we need to investigate the error and fix it.

Operation checks

Operation checks validate that a schema's changes won't break any operations that existing clients send to the graph.

Illustration of Studio checking a schema against existing operations

For example, let's say a web client regularly sends a GraphQL query to retrieve data for its homepage. If a schema change involves adding a required argument to a field in that query, it might break that client's existing operation if it doesn't include that argument! An operation check helps us guard against this potential failure, listing out the affected operations and allowing the team to address them.

Linter checks

Linter checks analyze your proposed schema changes for violations of formatting rules and other GraphQL best practices. GraphOS provides a set of default rules you can configure to suit your team's conventions. You can see a full list of rules in the Apollo documentation.

Some common schema conventions include: writing field names in camelCase, type names in PascalCase, and enums in SCREAMING_SNAKE_CASE.

How to run schema checks

There are two main ways to run schema checks using the Rover CLI. We can run schema checks locally in our terminal. We can also integrate schema checks into our CI pipelines to run automatically against new pull requests.

To perform a schema check for a subgraph, we use the rover subgraph check command with the following parameters:

rover subgraph check <GRAPH_REF> \
--schema <SCHEMA_FILE_PATH> \
--name <SUBGRAPH_NAME>

Note: The graph reference (or graph ref) tells Rover about our supergraph. A graph ref starts with the graph's ID, followed by an @ symbol, followed by the graph variant.

This command runs a build check first, then an operation check, then a linter check, and finally outputs the results in the command line. It also reports the results to GraphOS, so we can view them from your graph's Checks page.

Schema checks in the supergraph story

Let's revisit our story and zoom in to where schema checks occur and what happens when they fail, pass, or are actively overridden.

After making changes to a subgraph schema (whether that's adding, removing, or updating definitions), we first want to run schema checks locally using Rover.

First, Rover validates that a subgraph's schema changes can still compose successfully with the other subgraph schemas in the supergraph. By default, this check runs against the current variant of the graph, but we can also select any graph variant already registered in Studio.

If the build check succeeds, Rover runs an operation check immediately after. This validates that the schema's changes won't break any operations that existing clients send to the graph.

If either check fails, Rover provides a link to the Studio Checks page that contains more information about what went wrong.

If all the checks are successful, we can go ahead and follow the same process as before: we'll use Rover to publish the subgraph schema to the registry.

Illustration of schema checks fitting into the story of a supergraph. See description in paragraphs above for full outline of the process.

While we're on the subject of publishing schema changes, let's take a moment to touch on a useful feature of GraphOS: a launch.

Launch process

By publishing to the schema registry, we've triggered a launch in GraphOS.

A launch represents the complete process of making schema updates to any variant of a graph.

A launch starts with GraphOS attempting to compose the supergraph. If it fails, we'll see an error and the process stops there. Otherwise, a supergraph schema is produced. The supergraph schema is provided to Uplink and the GraphOS Router will fetch the latest schema.

We've successfully completed our schema updates to the graph!

Illustration of launches and how they fit into the story of a supergraph. See description in paragraphs above for full outline of the process.

And that's what schema checks and the launch process look like in our supergraph.

Practice

Types of schema checks
Schema checks identify potential failures from proposed schema changes. 
 
 checks validate that a schema follows GraphQL conventions. 
 
 checks validate that existing client operations won't break. 
 
 checks validate that the supergraph schema will still compose successfully.

Drag items from this box to the blanks above

  • Operation

  • Linter

  • Field

  • Build

  • Deprecated

  • Subgraph

To pick up a draggable item, press the space bar. While dragging, use the arrow keys to move the item. Press space again to drop the item in its new position, or press escape to cancel.
Which of the following statements about launches in GraphOS are true?

Key takeaways

  • Schema checks help identify potential failures caused by schema updates before they can cause issues in production.
  • Build checks validate that a subgraph's schema changes can still compose successfully with other subgraph schemas.
  • Operation checks validate that a schema's changes won't break any operations that existing clients are sending to the graph.
  • Linter checks validate that a schema follows formatting rules and conventions.
  • To run a schema check, we use the rover subgraph check command.
  • We can inspect the results of a schema check through the terminal or in the Studio Checks page.
  • A launch represents the complete process of making schema updates to any variant of a graph. It's triggered by a subgraph being published to the schema registry.

Up next

In the next three lessons, we'll see how schema checks work in our development workflow and how they can be automated in the CI/CD process.

Previous
Next

Share your questions and comments about this lesson

Your feedback helps us improve! If you're stuck or confused, let us know and we'll help you out. All comments are public and must follow the Apollo Code of Conduct. Note that comments that have been resolved or addressed may be removed.

You'll need a GitHub account to post below. Don't have one? Post in our Odyssey forum instead.

              variant

              Independent instances of a graph often used to represent different environments. Each variant has its own schema and own router.

              GraphOS

              A platform for building and managing a supergraph. It provides a management plane to test and ship changes and runtime capabilities to secure and monitor the graph.

              schema checks

              A GraphOS feature that ensures proposed subgraph schema changes successfully compose into a supergraph schema, don't break active clients, and follow best practices.

              schema checks

              A GraphOS feature that ensures proposed subgraph schema changes successfully compose into a supergraph schema, don't break active clients, and follow best practices.

              schema checks

              A GraphOS feature that ensures proposed subgraph schema changes successfully compose into a supergraph schema, don't break active clients, and follow best practices.

              supergraph

              A unified, federated graph composed of separate GraphQL APIs using Apollo Federation. Enables a microservices architecture that exposes a unified GraphQL API to clients.

              launch

              The process of applying a set of updates to a supergraph. Launches are usually triggered by making changes to one of your published subgraph schemas.

              GraphOS

              A platform for building and managing a supergraph. It provides a management plane to test and ship changes and runtime capabilities to secure and monitor the graph.

              subgraph schemas

              A schema for a subgraph server. A subgraph schema must be compliant with the GraphQL and Apollo Federation specs to be composed into a supergraph.

              operations

              A single query, mutation, or subscription that clients send to a GraphQL server to request or manipulate data.

              schema checks

              A GraphOS feature that ensures proposed subgraph schema changes successfully compose into a supergraph schema, don't break active clients, and follow best practices.

              schema checks

              A GraphOS feature that ensures proposed subgraph schema changes successfully compose into a supergraph schema, don't break active clients, and follow best practices.

              operation

              A single query, mutation, or subscription that clients send to a GraphQL server to request or manipulate data.

              subgraph

              A service in a federated GraphQL architecture. Acts as a module for a supergraph. Includes both GraphQL services and REST services integrated via Apollo Connectors.

              subgraph schemas

              A schema for a subgraph server. A subgraph schema must be compliant with the GraphQL and Apollo Federation specs to be composed into a supergraph.

              supergraph

              A unified, federated graph composed of separate GraphQL APIs using Apollo Federation. Enables a microservices architecture that exposes a unified GraphQL API to clients.

              subgraph

              A service in a federated GraphQL architecture. Acts as a module for a supergraph. Includes both GraphQL services and REST services integrated via Apollo Connectors.

              supergraph

              A unified, federated graph composed of separate GraphQL APIs using Apollo Federation. Enables a microservices architecture that exposes a unified GraphQL API to clients.

              operations

              A single query, mutation, or subscription that clients send to a GraphQL server to request or manipulate data.

              graph

              A schema-based data model representing how different data elements interconnect and can be accessed.

              GraphQL

              An open-source query language and specification for APIs that enables clients to request specific data, promoting efficiency and flexibility in data retrieval.

              query

              A request for specific data from a GraphQL server. Clients define the structure of the response, enabling precise and efficient data retrieval.

              argument

              A key-value pair associated with a particular schema field that lets operations pass data to that field's resolver.

              Argument values can be hardcoded as literal values (shown below for clarity) or provided via GraphQL variables (recommended).

              query GetHuman {
              human(id: "200") {
              name
              height(unit: "meters")
              }
              }
              field

              A unit of data that belongs to a type in a schema. Every GraphQL query requests one or more fields.

              type Author {
              # id, firstName, and lastName are all fields of the Author type
              id: Int!
              firstName: String
              lastName: String
              }
              query

              A request for specific data from a GraphQL server. Clients define the structure of the response, enabling precise and efficient data retrieval.

              operation

              A single query, mutation, or subscription that clients send to a GraphQL server to request or manipulate data.

              GraphQL

              An open-source query language and specification for APIs that enables clients to request specific data, promoting efficiency and flexibility in data retrieval.

              GraphOS

              A platform for building and managing a supergraph. It provides a management plane to test and ship changes and runtime capabilities to secure and monitor the graph.

              field

              A unit of data that belongs to a type in a schema. Every GraphQL query requests one or more fields.

              type Author {
              # id, firstName, and lastName are all fields of the Author type
              id: Int!
              firstName: String
              lastName: String
              }
              schema checks

              A GraphOS feature that ensures proposed subgraph schema changes successfully compose into a supergraph schema, don't break active clients, and follow best practices.

              Rover CLI

              Apollo's command-line interface for managing and maintaining graphs with GraphOS.

              subgraph

              A service in a federated GraphQL architecture. Acts as a module for a supergraph. Includes both GraphQL services and REST services integrated via Apollo Connectors.

              graph ref

              A unique identifier for a particular variant of a particular graph in GraphOS. Made up of a graph's unique ID and variant name with the following format: graph-id@variant-name.

              Rover

              Apollo's command-line interface for managing and maintaining graphs with GraphOS.

              supergraph

              A unified, federated graph composed of separate GraphQL APIs using Apollo Federation. Enables a microservices architecture that exposes a unified GraphQL API to clients.

              graph

              A schema-based data model representing how different data elements interconnect and can be accessed.

              variant

              Independent instances of a graph often used to represent different environments. Each variant has its own schema and own router.

              operation

              A single query, mutation, or subscription that clients send to a GraphQL server to request or manipulate data.

              GraphOS

              A platform for building and managing a supergraph. It provides a management plane to test and ship changes and runtime capabilities to secure and monitor the graph.

              schema checks

              A GraphOS feature that ensures proposed subgraph schema changes successfully compose into a supergraph schema, don't break active clients, and follow best practices.

              subgraph schema

              A schema for a subgraph server. A subgraph schema must be compliant with the GraphQL and Apollo Federation specs to be composed into a supergraph.

              schema checks

              A GraphOS feature that ensures proposed subgraph schema changes successfully compose into a supergraph schema, don't break active clients, and follow best practices.

              Rover

              Apollo's command-line interface for managing and maintaining graphs with GraphOS.

              Rover

              Apollo's command-line interface for managing and maintaining graphs with GraphOS.

              subgraph

              A service in a federated GraphQL architecture. Acts as a module for a supergraph. Includes both GraphQL services and REST services integrated via Apollo Connectors.

              subgraph schemas

              A schema for a subgraph server. A subgraph schema must be compliant with the GraphQL and Apollo Federation specs to be composed into a supergraph.

              supergraph

              A unified, federated graph composed of separate GraphQL APIs using Apollo Federation. Enables a microservices architecture that exposes a unified GraphQL API to clients.

              variant

              Independent instances of a graph often used to represent different environments. Each variant has its own schema and own router.

              graph

              A schema-based data model representing how different data elements interconnect and can be accessed.

              Rover

              Apollo's command-line interface for managing and maintaining graphs with GraphOS.

              operation

              A single query, mutation, or subscription that clients send to a GraphQL server to request or manipulate data.

              graph

              A schema-based data model representing how different data elements interconnect and can be accessed.

              Rover

              Apollo's command-line interface for managing and maintaining graphs with GraphOS.

              Rover

              Apollo's command-line interface for managing and maintaining graphs with GraphOS.

              subgraph schema

              A schema for a subgraph server. A subgraph schema must be compliant with the GraphQL and Apollo Federation specs to be composed into a supergraph.

              GraphOS

              A platform for building and managing a supergraph. It provides a management plane to test and ship changes and runtime capabilities to secure and monitor the graph.

              GraphOS

              A platform for building and managing a supergraph. It provides a management plane to test and ship changes and runtime capabilities to secure and monitor the graph.

              launch

              The process of applying a set of updates to a supergraph. Launches are usually triggered by making changes to one of your published subgraph schemas.

              variant

              Independent instances of a graph often used to represent different environments. Each variant has its own schema and own router.

              graph

              A schema-based data model representing how different data elements interconnect and can be accessed.

              launch

              The process of applying a set of updates to a supergraph. Launches are usually triggered by making changes to one of your published subgraph schemas.

              GraphOS

              A platform for building and managing a supergraph. It provides a management plane to test and ship changes and runtime capabilities to secure and monitor the graph.

              supergraph

              A unified, federated graph composed of separate GraphQL APIs using Apollo Federation. Enables a microservices architecture that exposes a unified GraphQL API to clients.

              supergraph schema

              A special type of GraphQL schema that is created by declaratively combining one or more subgraph schemas using the Apollo Federation specification.

              Uplink

              An Apollo-hosted endpoint for serving supergraph configurations to GraphOS Router and @apollo/gateway. Also serves the Enterprise license to GraphOS Router.

              GraphOS Router

              A scalable runtime for supergraphs that's fully integrated with GraphOS and based on the Apollo Router Core. Can be cloud- or self-hosted.

              graph

              A schema-based data model representing how different data elements interconnect and can be accessed.

              schema checks

              A GraphOS feature that ensures proposed subgraph schema changes successfully compose into a supergraph schema, don't break active clients, and follow best practices.

              launch

              The process of applying a set of updates to a supergraph. Launches are usually triggered by making changes to one of your published subgraph schemas.

              supergraph

              A unified, federated graph composed of separate GraphQL APIs using Apollo Federation. Enables a microservices architecture that exposes a unified GraphQL API to clients.

              Schema checks

              A GraphOS feature that ensures proposed subgraph schema changes successfully compose into a supergraph schema, don't break active clients, and follow best practices.

              subgraph

              A service in a federated GraphQL architecture. Acts as a module for a supergraph. Includes both GraphQL services and REST services integrated via Apollo Connectors.

              subgraph schemas

              A schema for a subgraph server. A subgraph schema must be compliant with the GraphQL and Apollo Federation specs to be composed into a supergraph.

              Operation

              A single query, mutation, or subscription that clients send to a GraphQL server to request or manipulate data.

              graph

              A schema-based data model representing how different data elements interconnect and can be accessed.

              launch

              The process of applying a set of updates to a supergraph. Launches are usually triggered by making changes to one of your published subgraph schemas.

              variant

              Independent instances of a graph often used to represent different environments. Each variant has its own schema and own router.

              graph

              A schema-based data model representing how different data elements interconnect and can be accessed.

              subgraph

              A service in a federated GraphQL architecture. Acts as a module for a supergraph. Includes both GraphQL services and REST services integrated via Apollo Connectors.

              schema checks

              A GraphOS feature that ensures proposed subgraph schema changes successfully compose into a supergraph schema, don't break active clients, and follow best practices.

              NEW COURSE ALERT

              Introducing Apollo Connectors

              Connectors are the new and easy way to get started with GraphQL, using existing REST APIs.

              Say goodbye to GraphQL servers and resolvers—now, everything happens in the schema!

              Take the course