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
3. Publishing to a graph variant
2m

Overview

Awesome, we know how graph variants can be useful in our development flow, so let's put them to use. In this lesson, we will:

  • Create a staging graph variant
  • Learn how to push a subgraph schema to a graph variant
  • Access and explore variants in GraphOS

Creating a staging variant

Right now, both the staging and production versions of the GraphOS Router are using the production version of the supergraph schema. This means that when we publish changes to our staging subgraphs, the schema used by our live production router also changes. And that's not great, because if our changes accidentally break something, things will be broken in both our staging and production routers. We need a staging graph variant for our staging version of the router to use.

Let's take a look at how to create a staging variant. We'll start by setting up the staging variant with our production graph's current state, so that we have a baseline to work from before we make our feature additions.

To create a new variant, we'll use the Rover CLI again. In fact, you're probably already familiar with the command we'll use: rover subgraph publish.

You might recall that the first argument of this command is the graph ref. The graph ref is the name of the graph, followed by @ and the name of the variant.

airlock-managed-fed@current

In Voyage I, we used the default current variant, but we can also specify a different variant. In this case, we'll use the name staging. If this variant doesn't already exist, GraphOS will create it for us.

Here's how we'd publish the accounts subgraph schema to the staging variant of our graph:

rover subgraph publish airlock-managed-fed@staging \
--schema "accounts.graphql" \
--name accounts \
--routing-url "https://staging-airlock-accounts.com"

Note that the routing-url value points to the subgraph's staging environment, not the production environment.

After running the rover subgraph publish command above, we'll see this in the terminal:

Publishing SDL to airlock-managed-fed@staging (subgraph: accounts)
using credentials from the default profile.
A new subgraph called 'accounts' for the 'airlock-managed-fed@staging' graph was created.
The supergraph schema for the 'airlock-managed-fed@staging' graph was updated,
composed from the updated 'accounts' subgraph.

After the schema is published to the staging variant, Studio will reflect this new addition. Under the graph's name on the homepage, we can see a new variant has been added with the name staging.

https://studio.apollographql.com
Screenshot of Studio showing the staging variant in the list of variants.

We can click on the new staging variant to see the current schema for this graph. So far, it only consists of the accounts subgraph that we just registered.

https://studio.apollographql.com
Screenshot of Studio showing the staging variant with the accounts subgraph registered.

We'll also need to register all the other subgraphs to the new staging variant: listings, bookings, reviews, and payments. The values for the schema, name, and routing-url options will differ for each, but the graph name and the variant will stay the same!

After publishing all the other subgraphs, we can see them in our staging variant schema:

https://studio.apollographql.com
Screenshot of Studio showing the staging variant with all five subgraphs registered.

Awesome, the staging graph variant is now set up with all of the subgraphs for Airlock! Right now, the staging variant schema is in the exact same state as the current variant schema. We've got our baseline ready before we start making feature additions or schema changes.

The last thing we need to do is make sure the staging graph variant is connected to the endpoint for the staging router.

We can do this in the variant's homepage by clicking on Connection Settings, and setting the endpoint for the staging router URL.

https://studio.apollographql.com
Screenshot of Studio showing the Connection Settings modal, where the staging router endpoint is set

All right, we're ready to proceed with our changes for Project Galactic Coordinates.

Practice

Which of these is the correct way to publish a subgraph schema to a specific variant?

Key takeaways

  • We can publish a schema to a specific variant by using the Rover command rover subgraph publish and specifying the graph variant name after the @ symbol in the graph ref.

Up next

The Listings Team has been hard at work, and they're now ready to share their schema updates so that other teams can also start contributing to Project Galactic Coordinates.

In the next lesson, we'll see how they can use schema checks to confidently push their schema changes to the registry.

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.

              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.

              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.

              variants

              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.

              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.

              supergraph schema

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

              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.

              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.

              variant

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

              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.

              variant

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

              Rover CLI

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

              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")
              }
              }
              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.

              variant

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

              variant

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

              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.

              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.

              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.

              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.

              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.

              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.

              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.

              variant

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

              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.

              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.

              variant

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

              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.

              variant

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

              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.

              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.

              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.

              variant

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

              Rover

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

              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 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.

              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