5. Publishing to the schema registry
5m

Overview

It's time to introduce an integral part of : the schema registry!

In this lesson, we will:

  • Learn about the schema registry and its uses
  • Learn about the process
  • Publish a schema to the schema registry using the
  • Inspect the results of a in Studio

What's the schema registry?

At its core, the schema registry is a version control system for our schema. It stores our schema's change history, tracking the types and that were added, modified, and removed. The registry powers almost every feature in .

Similar to how we commit and push changes to our codebase to a Git repository, we should push every new version of our to the registry. The registry takes care of tracking all the subgraphs and composing them into one . It's also thanks to the registry that we can run , as we did in the previous lesson. checks our schema changes against the schema stored in the registry.

In this course, we're starting small with just one in our . As we start adding more subgraphs, we'll continue to make use of the power of the schema registry!

When we publish a new version of a to the registry, we trigger a in .

The launch process

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

When the schema registry gets a new or updated version of a , it starts to build the . The schema registry attempts to combine all of the schemas from its registered into a single supergraph schema. This process is also known as composition.

If fails, we'll see an error in Studio, and the process stops there. No stress: we can use the error messages to fix the issue in our , and then try publishing the subgraph with again.

If succeeds and there are no validation errors, the schema registry produces a .

The schema registry automatically sends the to an internal service within called Apollo Uplink. Uplink is a server that stores the latest for each graph. The fetches the latest schema from Uplink and uses this new schema to respond to client requests.

With that, the completes successfully!

Coordinating schema and code changes

So far, we've only been talking about schema changes and how they should be published to . But we can't forget about our codebase changes! These include the changes we made to the functions to make our schema work and the schema file itself. We need to deploy our local changes to production.

To coordinate both schema and code changes, here's the plan:

  1. Merge our codebase changes (the changes we made to schema.graphql and resolvers.js) to the main branch of our GitHub repository.

  2. Deploy the runtime code for the to Railway (this happens automatically, Railway is listening for changes to our GitHub main branch).

  3. Publish the to (which triggers the process).

Ideally, this is all taken care of by our CI/CD pipelines. First, we'll walk through what this process looks like manually, to get familiar with the commands we'll need and where to find the results. In the next lesson, we'll set up a CI/CD pipeline using GitHub Actions to take care of it automatically.

Note: Depending on your deployment platforms of choice, your plan may look different from the one we've outlined! For example, Railway automatically deploys the latest changes from our main branch, but you might want to have more control over this process, or deploy from a different branch. Maybe you have a pre-production environment to test changes before releasing to production. We cover what the release process might look like with a staging environment in the mix in the Voyage III course. You can also read more about the general process of deploying changes in this Apollo technote.

Merging codebase changes

All right, let's get to it! First, let's merge our codebase changes.

Let's commit the changes we made earlier and push them directly to the main branch. (We're in tutorial land, so we're okay with doing this! In the next lesson, you'll see a process that reflects a real-world scenario more closely using CI/CD workflows).

  1. Open up a new terminal.

  2. Add the files we've changed.

    git add schema.graphql src/resolvers
  3. Commit the changes with a clear message explaining what we've done.

    git commit -m "Deprecate Ingredient.text field. Use detailedDescription instead."
  4. Push the changes to the GitHub repo.

    git push -u origin main

That's the first step done!

  1. Merge our codebase changes to the main branch of our GitHub repository.

  2. ⏭️ Deploy the runtime code for the subgraph server to Railway.

  3. Publish the to .

Step 2 doesn't need much work from us! Once our changes have landed in the main branch, Railway will automatically start its deployment process.

Head over to your Railway app and watch the loading bar until it says it has been successfully deployed with no issues! If you navigate to your server URL, there won't be any visible changes, but we know that behind the scenes, this is ready with a new and a deprecated field!

  1. Merge our codebase changes to the main branch of our GitHub repository.

  2. Deploy the runtime code for the subgraph server to Railway.

  3. ⏭️ Publish the subgraph schema to GraphOS.

Let's tackle the last step!

rover subgraph publish

We need to publish our new to .

To do this, we'll use the 's rover subgraph publish command with the following parameters:

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

It looks pretty similar to the rover subgraph check command!

Note: Remember, you can find your erence in Studio, at the top of the graph's README page.

Publishing our subgraph changes

Let's do it! In a terminal window, paste in the rover subgraph publish command. Make sure you replace the parameters with your own values.

rover subgraph publish learning-cats-supergraph@current \
--schema schema.graphql \
--name space-courses

If all goes well, we should see the terminal output with a message confirming that the has been published and the has been updated!

Inspecting a launch in Studio

What happens after a schema is published to the registry? A starts! Let's take a peek at that process in Studio.

Navigate to the Launches page. Click on the latest in the list.

https://studio.apollographql.com

The Studio Launches page showing the results of the latest launch

We can see that the Launch Sequence section for this specific follows the steps we had talked about earlier:

  • Build Completed refers to the process of building a (also known as ).
  • Schema Published refers to the made available to Apollo Uplink.
  • Launch Completed is self-explanatory! Our launch successfully completed! 🎉

On the right-hand side, we can also take a look at the output and a summary of our schema changes.

https://studio.apollographql.com

The Studio Launches page showing the supergraph schema button and a summary of changes

If everything looks good to go, we should be able to for the new detailedDescription for an ingredient.

Let's go to Explorer and run a to retrieve a random recipe's ingredients and a detailed description of each.

query GetRandomRecipeIngredients {
randomRecipe {
ingredients {
detailedDescription
}
}
}

You should be seeing data come back! Let's try another one, adding text in the this time.

query GetRandomRecipeIngredients {
randomRecipe {
ingredients {
detailedDescription
text
}
}
}

The still runs and comes back successfully, but we get a warning in the Explorer (that yellow squiggly line!) that text has been deprecated and not to use it anymore.

Our launch was successful! 🎉

Practice

In which ways the Apollo schema registry is comparable to a Git version control system?

Key takeaways

  • The schema registry is a version control system for our schema. It stores our schema's change history, tracking the types and that were added, modified, and removed. The registry takes care of tracking all the and composing them into one .
  • A launch represents the complete process of making schema updates to a . A is triggered when a schema is published to .
  • To publish a , use the rover subgraph publish command.
  • We can inspect the results of a through the Studio Launches page.

Up next

Awesome job! We've made changes to our safely and confidently with the help of . We did all this manually, running and publish commands from the terminal, but this work should really live in an automated CI/CD pipeline. In the next lesson, we'll get one set up!

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.