Docs
Try Apollo Studio

Apollo Router quickstart

Run the Apollo Router with Apollo-hosted subgraphs


Hello! This tutorial walks you through installing the Apollo Router and running it in front of some Apollo-hosted example subgraphs.

1. Download and extract the Apollo Router binary

Download options

Note: The Apollo Router is made available under the Elastic License v2.0 (ELv2). Read our licensing page for more details.

Automatic download (Linux, OSX, WSL)

If you have a bash-compatible terminal, you can download the latest version of the Apollo Router directly to your current directory with the following command:

curl -sSL https://router.apollo.dev/download/nix/latest | sh

Manual download

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. You can also open an issue on GitHub for us to consider adding new architectures.

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

Running the binary

You can now try running the Apollo Router from your project's root directory with the following command:

./dist/router

If you do, you'll get the following output:

APOLLO ROUTER <version>
⚠️ The Apollo Router requires a composed supergraph schema at startup. ⚠️
👉 DO ONE:
* Pass a local schema file with the '--supergraph' option:
$ ./router --supergraph <file_path>
* Fetch a registered schema from Apollo Studio by setting
these environment variables:
$ APOLLO_KEY="..." APOLLO_GRAPH_REF="..." ./router
For details, see the Apollo docs:
https://www.apollographql.com/docs/router/managed-federation/setup
🔬 TESTING THINGS OUT?
1. Download an example supergraph schema with Apollo-hosted subgraphs:
$ curl -L https://supergraph.demo.starstuff.dev/ > starstuff.graphql
2. Run the Apollo Router with the supergraph schema:
$ ./router --supergraph starstuff.graphql

This is because Apollo Router requires a supergraph schema and we aren't providing it one! Let's fix that.

2. Download the example supergraph schema

For this quickstart, we're using example Apollo-hosted subgraphs, along with an example supergraph schema that's composed from those subgraph 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!

3. Run the router with the default configuration

Now from your project root, run the following:

./dist/router --supergraph supergraph-schema.graphql

The console output should look like the following:

2022-03-14T11:56:55.900207Z INFO apollo_router: Starting Apollo Router
2022-03-14T11:56:56.000707Z INFO apollo_router: Listening on http://127.0.0.1:4000 🚀

That's it! Visit http://127.0.0.1:4000 to open Apollo Sandbox. You can inspect the entire federated graph and run your first queries against the Apollo Router!

Next steps

Now that you know how to run Apollo Router with a supergraph schema, you can:

Edit on GitHub
Previous
Introduction
Next
Moving from @apollo/gateway