Overview
You're excited to start making changes, but let's make sure we actually have a supergraph to make changes to. In this lesson, we will:
- Deploy the recipes subgraph server using Railway
- Change a subgraph's routing URL
- Set up and authenticate the Rover CLI
Deploying your copy of the recipes subgraph server
This course is all about making changes to your supergraph, which involves making changes to its subgraph! In the "GraphOS: Basics" course, we used an existing deployed version of the Poetic Plates API (which became our first subgraph called recipes). Now, let's make sure you have your own copy to make changes to.
We'll be using Railway to deploy our subgraph, but feel free to use any other hosting platform you're familiar with.
To get started, click the button below ⬇️
Then, walk through the deploy setup steps in Railway.
Deploy successful on Railway? Great! Last thing: we want to query our server at a public URL on the internet. To do this, we'll need to generate a domain.
Go to your app's Settings tab, and click the Generate Domain button under the Domains header.
This will automatically create our production URL. After a few minutes, you should see a page showing that your server is ready to query.
Cloning the repo
Next, let's clone the repo and make sure we're set up for local development.
To find the repo, head over to your Railway app's Settings, scroll down to Service and find the Source repo link.
Click the link to find your copy of the GitHub repo.
Clone the repo to your local environment.
Open it up in your code editor.
Run
npm install
in a terminal.Run
npm run dev
. This starts up the server in development mode, which means changes you make in your files will automatically restart the server. If all goes well, when you open up http://localhost:4001, you should see Explorer with the schema ready to query.Run the test query below and confirm that you get data back!
query GetRandomRecipe {randomRecipe {idname}}
Supergraph setup
Our subgraph is ready to be used, so next, let's get our cloud supergraph set up!
If you've already completed the previous course, then you should already have an existing cloud supergraph! Currently, it's using the Apollo-hosted subgraph though. We'll want to fix that to point to your own deploy URL hosted on Railway from the previous step.
Edit the recipes
subgraph routing URL
Navigate to GraphOS Studio and open up your supergraph's homepage.
Head over to the Subgraphs page.
You should already see the
recipes
subgraph in the list, with the routing URL pointing to https://poetic-plates-recipes-api.herokuapp.com/. We need to change this to your Railway URL.Click the three dots beside the
recipes
subgraph and click Edit routing url.https://studio.apollographql.com/Paste in the URL you generated from Railway, then hit Update.
https://studio.apollographql.com/It'll take a few moments for the changes to land and deploy to our router!
Check your supergraph
In Studio, navigate to the Explorer page and paste this query.
query GetRandomRecipe {randomRecipe {idnamereadyTimeservingsingredients {text}}}
You should get some data back!
Rover setup
Rover is Apollo's command line interface (CLI) tool that helps developers work with graphs and interact with GraphOS. It's a handy and versatile tool that can be used for both local development and CI/CD. We can use it to run checks, publish schemas to the schema registry, and much more.
Installing Rover
Open up a terminal and run the install command that suits your computer's environment:
For Linux / Mac OS:
curl -sSL https://rover.apollo.dev/nix/latest | shFor Windows PowerShell installer
iwr 'https://rover.apollo.dev/win/latest' | iexNote: You can find other installation methods in the Apollo documentation.
Verify that the installation completed successfully by running
rover
anywhere in the terminal.If it outputs a list of options and subcommands for using Rover, great! The CLI is installed and ready to go.
Authenticating Rover
We need an API key to authenticate Rover! Since we're starting out working locally, we'll use a personal API key. (There's another type of API key called graph API keys that are used for CI/CD environments, which we'll take a look at later on!)
In Studio, click on your profile picture on the top right side, then Personal Settings.
Click API Keys.
Click Create new key.
https://github.comGive it a name, like "Local Dev".
Copy your key—you won't be able to see it again!
In a terminal, run:
rover config authThen paste in your API key.
To check if it worked, run:
rover config whoamiAnd you should see your profile information displayed. You're all set!
Key takeaways
- To create a supergraph, you need your GraphQL API endpoint. This becomes the first subgraph of the supergraph.
- You can change the routing URL of a subgraph through the Studio Subgraphs page.
- When working on your local development machine, you can authenticate Rover using a personal API key.
Up next
We're all set up with our subgraph, supergraph, and the Rover, whew! All the pieces we need. This is great, and everything works fine, but we're here to learn what to do to make changes to our supergraph safely and confidently. Let's dive in.
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.