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
2. Variants in a supergraph
2m

Overview

New features are exciting, and we're itching to get Project Galactic Coordinates out into the world. But we need to take care not to break existing functionality while giving clients a chance to test out these new queries and fields in a separate, safe environment (like our staging environment).

Right now, we only have the production version of the supergraph schema in the registry. Ideally, what we want is something similar to our Heroku setup: separate environments for staging and production versions of our graph, so that we can test out our schema changes before publishing them to our live site. Luckily, GraphOS has a feature for just that: graph variants!

In this lesson, we will:

  • Learn what a graph variant is
  • Learn how graph variants help our development workflow

What are graph variants?

A graph variant is an instance of a graph that runs in a specific environment (such as staging or production). In GraphOS, each variant of a graph has its own schema, metrics, change history, and operation history.

So far, we've been working with only one version of our graph: the version that's currently running in production. This is actually our very first variant, and its default name is current. The GraphOS Router running in production is connected to this graph variant through the environment variables we had previously set up (APOLLO_KEY and APOLLO_GRAPH_REF).

Using graph variants helps us test and validate changes to our schema without committing to them right away in our production environment. The way you use graph variants can vary depending on your team and company's use cases, along with your deployment practices.

For Airlock, we want to set up a staging graph variant and connect it to the staging version of our router (using the corresponding environment variables). We'll look at how to do this in the next lesson.

Note: We'll be focusing on a federated graph, or supergraph, for this course, but graph variants can also be used for non-federated graphs.

Variants in the supergraph

Let's revisit our journey of a supergraph.

Journey of a supergraph. See below for a detailed image description.
  1. Teams build their own subgraphs.

  2. A team creates a new deployed graph in GraphOS Studio.

  3. Each team publishes their subgraph schema to the registry using the Rover CLI.

  4. GraphOS attempts to compose the supergraph schema. If composition fails, the team has composition errors to fix. If composition succeeds, the supergraph schema is made available at Uplink.

  5. The router polls Uplink for the latest version of the supergraph schema. Now it's ready to receive incoming GraphQL operations from clients and coordinate data across subgraphs!

We learned in Voyage I that teams build their own subgraphs and publish their subgraph schemas to the Apollo schema registry.

We also have the option to choose which variant to publish a subgraph schema to. If we don't specify a variant name, our changes are published by default to the current variant. (We'll take a closer look at how to publish to a specific variant in the next lesson.)

An illustration of a subgraph facing two different paths: one to the `current` variant and the other to a `staging` variant

After we publish the subgraph to a variant, the rest of the story stays the same! This variant provides its schema to Apollo Uplink, which the router can then fetch.

We can have as many variants as we want. This makes it easy to spin up new graph versions to test and play with before committing to the production environment.

An illustration of duplicate schema registries representing different variants, and how subgraphs can choose to publish to any of them.

Practice

Which of the following statements are true about graph variants in GraphOS?

Key takeaways

  • A graph variant represents an instance of a graph that runs in a specific environment.
  • The managed federation process stays the same as before, with the added option of choosing which variant to publish a schema to.
  • Graph variants are available for both federated and non-federated graphs.

Up next

In the next lesson, we'll create a graph variant for the staging environment.

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.

              fields

              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
              }
              supergraph schema

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

              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.

              variants

              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.

              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.

              variants

              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.

              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.

              variant

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

              metrics

              Measurements of the router's behavior that can be exported and monitored, for example, the number of in-flight requests.

              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.

              variant

              Independent instances of a graph often used to represent different environments. Each variant has its own schema and own 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.

              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.

              variants

              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.

              variant

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

              router

              The single access point for a federated GraphQL architecture. It receives incoming operations and intelligently routes them across component services before returning a unified response.

              graph

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

              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.

              variants

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

              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.

              subgraphs

              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

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

              GraphOS Studio

              The web interface for GraphOS, which provides graph, variant, and organization management, metrics visualization, schema pipeline tools and more.

              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.

              Rover CLI

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

              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 schema

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

              composition

              The process of combining subgraph schemas into a supergraph schema. A supergraph schema includes all definitions from subgraph schemas and additional metadata.

              Uplink

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

              router

              The single access point for a federated GraphQL architecture. It receives incoming operations and intelligently routes them across component services before returning a unified response.

              Uplink

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

              supergraph schema

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

              GraphQL

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

              operations

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

              subgraphs

              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.

              subgraphs

              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.

              variant

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

              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.

              variant

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

              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.

              variant

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

              Apollo Uplink

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

              router

              The single access point for a federated GraphQL architecture. It receives incoming operations and intelligently routes them across component services before returning a unified response.

              variants

              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.

              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.

              managed federation

              A managed approach to supergraph composition and deployment. With managed federation, subgraphs publish their schemas to GraphOS, which validates, composes, and deploys the supergraph schema.

              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.

              variants

              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.

              variant

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

              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