3. Publishing to a graph variant
4m

Overview

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

  • Create a staging graph
  • Learn how to push a to a graph
  • Access and explore s 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 s, 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 for our staging version of the to use.

Let's take a look at how to create a staging . We'll start by setting up the staging 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 , we'll use the 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 .

airlock-managed-fed@current

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

Here's how we'd publish the accounts to the staging 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 '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 , 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 Apollo Studio showing the staging variant in the list of variants.

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

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

We'll also need to register all the other s to the new staging : 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 will stay the same!

After publishing all the other s, we can see them in our staging :

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

Awesome, the staging graph is now set up with all of the s for Airlock! Right now, the staging is in the exact same state as the current . 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 is connected to the endpoint for the staging .

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

https://studio.apollographql.com
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.

Practice

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

Key takeaways

  • We can publish a to a specific by using the command rover subgraph publish and specifying the graph 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 .

Previous

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.