Apollo Router quickstart
Run the Apollo Router with Apollo-hosted subgraphs
Hello! This tutorial walks you through installing Apollo Router and running it in front of some Apollo-hosted example subgraphs.
Go to the Apollo Router's GitHub Releases page and download the latest
.tar.gz file that matches your system. Currently, tarballs are available for the following:
- Linux (x86_64)
- macOS (x86_64)
- Windows (x86_64)
If a tarball for your system or architecture isn't available, you can build and run Apollo Router from source.
After downloading, extract the file by running the following from a new project directory, substituting the path to the tarball:
tar -xf path/to/file.tar.gz
You can now try running Apollo Router from your project's root directory with the following command:
If you do, you'll get the following error:
Error: 💫 Apollo Router requires a supergraph to be set using '--supergraph': $ ./router --supergraph <file>` 🪐 The supergraph can be built or downloaded from the Apollo Registry using the Rover CLI. To find out how, see: https://www.apollographql.com/docs/rover/supergraphs/. 🧪 If you're just experimenting, you can download and use an example supergraph with pre-deployed subgraphs: $ curl -L https://supergraph.demo.starstuff.dev/ > starstuff.graphql Then run Apollo Router with that supergraph: $ ./router --supergraph starstuff.graphql
This is because Apollo Router requires a supergraph schema as input! Let's obtain one.
For this quickstart, we're using example Apollo-hosted subgraphs, along with an example supergraph schema that's composed from their schemas.
From your project's root directory, run the following:
curl -sSL https://supergraph.demo.starstuff.dev/ > supergraph-schema.graphql
This saves a
supergraph-schema.graphql file with the following contents:
This file is all that Apollo Router needs to communicate with our subgraphs!
Now from your project root, run the following:
./dist/router --supergraph supergraph-schema.graphql
The console output should look like the following:
Nov 02 17:08:09.926 INFO router: Starting Apollo Router Nov 02 17:08:10.279 INFO router: Listening on http://127.0.0.1:4000 🚀
That's it! Visit
localhost:4000 to open the Apollo Sandbox Explorer. You can inspect the entire federated graph and run your first queries against Apollo Router!
Now that you know how to run Apollo Router with a supergraph schema, you can:
- Try running Apollo Router in front of test instances of your own subgraphs
- Learn about advanced configuration options