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.
Self-hosting the Apollo Router is part of the Apollo Enterprise plan. For other organizations, you should instead create a cloud supergraph, which provisions and hosts your router for you.
The Apollo Router is made available under the Elastic License v2.0 (ELv2). For details, see our licensing page.
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
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)
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 --strip-components=1
If you omit the
--strip-components=1 option, the
router executable is installed in a
You can now run the Apollo Router from your project's root directory with the following command:
If you do, you'll get output similar to the following:
Apollo Router <version> // (c) Apollo Graph, Inc. // Licensed as ELv2 (https://go.apollo.dev/elv2)⚠️ 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 settingthese environment variables:$ APOLLO_KEY="..." APOLLO_GRAPH_REF="..." ./routerFor 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.graphql2. Run the Apollo Router in development mode with the supergraph schema:$ ./router --dev --supergraph starstuff.graphql
This is because Apollo Router requires a supergraph schema and we aren't providing it one! Let's fix that.
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 the router needs to communicate with our subgraphs!
Now from your project root, run the following:
./router --dev --supergraph supergraph-schema.graphql
The console output should look like the following:
2022-06-29T22:23:24.266542Z INFO apollo_router::executable: Apollo Router v0.9.5 // (c) Apollo Graph, Inc. // Licensed as ELv2 (https://go.apollo.dev/elv2)2022-06-29T22:23:24.488286Z INFO apollo_router::router: starting Apollo Router2022-06-29T22:23:25.774334Z INFO apollo_router::axum_http_server_factory: GraphQL endpoint exposed at http://127.0.0.1:4000/ 🚀
That's it! Running the Router with the
--dev flag enables a development mode that exposes Apollo Sandbox so you can run queries against the Apollo Router. This flag also relaxes some defaults to provide a better development experience (e.g., it exposes subgraph error messages), so you should always exclude this flag when running the router in a non-development environment.
http://127.0.0.1:4000 to open Apollo Sandbox, inspect your entire supergraph, and run your first queries!
⚠️ Do not use the
--dev flag in production! If you want to replicate any development mode functionality in production, modify your YAML configuration file instead.
--dev is equivalent to running
./router --hot-reload with the following configuration:
sandbox:enabled: truesupergraph:introspection: trueinclude_subgraph_errors:all: trueplugins:experimental.expose_query_plan: true
Now that you know how to run Apollo Router with a supergraph schema, you can: