3. Publishing to a graph variant


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 Apollo Studio

Creating a staging variant

Right now, both the staging and production versions of the are using the production version of the . This means that when we publish changes to our staging subgraphs, the used by our live production also changes. And that's not great, because if our changes accidentally break something, things will be broken in both our staging and production s. We need a staging graph variant for our staging version of the 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 of this command is the graph ref. The graph ref is the name of the graph, followed by @ and the name of the variant.


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 on our Studio graph, Studio will create it for us.

Here's how we'd publish the accounts subgraph 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 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.

Screenshot of Apollo Studio showing the staging variant in the list of variants.

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

Screenshot of Apollo 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 :

Screenshot of Apollo 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 is in the exact same state as the current variant . We've got our baseline ready before we start making feature additions or changes.

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

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

Screenshot of Apollo 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.


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 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 changes to the .