Docs
Try Apollo Studio

Configuring the Apollo Router

Command arguments and YAML config


For installation instructions, see the quickstart.

You run the Apollo Router with the following command (assuming you're in the same directory as the router executable):

./router --config router.yaml --supergraph supergraph-schema.graphql

Arguments for this command are described below.

Environment variables

To use managed federation set these environment variables when running the router:

APOLLO_KEY="..." APOLLO_GRAPH_REF="..." ./router
Argument / Environment VariableDescription
APOLLO_GRAPH_REF

The graph ref of the registered Apollo graph and variant that the router fetches its supergraph schema from.

One of this or -s / --supergraph is required.

If you provide this argument, you must also provide APOLLO_KEY.

APOLLO_KEY

The graph API key that the Apollo Router should use to authenticate with Apollo Studio when fetching its supergraph schema.

If you provide the APOLLO_GRAPH_REF env variable, this argument is required.

Command arguments

Where indicated, some of these arguments can also be set via an environment variable. Command-line arguments always take precedence over environment variables if an option is provided both ways.

Argument / Environment VariableDescription
-s / --supergraph

APOLLO_ROUTER_SUPERGRAPH_PATH

The absolute or relative path to the Apollo Router's supergraph schema.

To learn how to compose your supergraph schema with the Rover CLI, see the Federation quickstart.

One of this or env APOLLO_GRAPH_REF is required.

-c / --config

APOLLO_ROUTER_CONFIG_PATH

The absolute or relative path to the router's optional YAML configuration file.

--log

APOLLO_ROUTER_LOG

The log level, indicating the most severe log message type to include. In ascending order of verbosity, can be one of: off, error, warn, info, debug, or trace.

The default value is info.

--hr / --hot-reload

APOLLO_ROUTER_HOT_RELOAD

If provided, the router watches for changes to its schema and configuration files and reloads them automatically without downtime.

APOLLO_UPLINK_ENDPOINTS

The Apollo Uplink URL that the Apollo Router should poll to fetch its latest supergraph schema.

Currently, this argument supports providing only a single URL.

For default behavior and possible values, see Apollo Uplink.

APOLLO_UPLINK_POLL_INTERVAL

The amount of time between polls to Apollo Uplink.

The default value is 10s, which is also the minimum allowed value.

--schema

Prints out a JSON schema of the configuration file, including plugin configuration (see below).

-V / --version

Prints out the Apollo Router's version.

YAML config file

The Apollo Router takes an optional YAML configuration file as input via the --config option. If the --hot-reload flag is also passed (or the APOLLO_ROUTER_HOT_RELOAD environment variable is set to true), the router will automatically restart when changes to the configuration file are made.

This file enables you to customize the router's behavior in many ways:

Listen address

By default, the router starts an HTTP server that listens on 127.0.0.1:4000. You can specify a different address like so:

router_unix.yaml
#
# server: Configuration of the HTTP server
#
server:
# The socket address and port to listen on
# (Defaults to 127.0.0.1:4000)
listen: 127.0.0.1

The router can also listen on a Unix socket (not supported on Windows):

router_unix.yaml
server:
# Absolute path to a Unix socket
listen: /tmp/router.sock

Endpoint path

By default, the router starts an HTTP server that exposes a POST/GET endpoint at path /.

You can change this path by setting server.endpoint:

router.yaml
#
# server: Configuration of the HTTP server
#
server:
# The exposed endpoint to answer to GraphQL queries
# (Defaults to /)
endpoint: /graphql

The endpoint path must start with /.

Path parameters and wildcards are supported. For example:

  • /:my_dynamic_prefix/graphql matches both /my_project_a/graphql and /my_project_b/graphql.
  • /graphql/* matches /graphql/my_project_a and /graphql/my_project_b.

Note: The router does not support wildcards in the middle of a path (e.g., /*/graphql). Instead, use a path parameter.

Introspection

By default, the router answers to some introspection queries. You can override this behavior to disable the introspection like so:

router.yaml
#
# server: Configuration of the HTTP server
#
server:
introspection: false

Landing page

By default, the router displays a landing page if you access its endpoint path via your browser. You can override this behavior to disable the landing page like so:

router.yaml
#
# server: Configuration of the HTTP server
#
server:
landing_page: false

Subgraph routing URLs

By default, the Apollo Router extracts the routing URL for each of your subgraphs from the composed supergraph schema you provide it. In most cases, no additional configuration is required.

However, if you do need to override a particular subgraph's routing URL (for example, to handle changing network topography), you can do so in your YAML configuration file with the override_subgraph_url option:

router.yaml
override_subgraph_url:
accounts: http://localhost:8080

In this example, the accounts subgraph URL is overridden to point to http://localhost:8080. The URL specified in the supergraph schema is ignored.

Subgraphs not included in the override_subgraph_url list continue to use the routing URL specified in the supergraph schema.

HTTP header rules

See Sending HTTP headers to subgraphs.

Cross-Origin Resource Sharing (CORS)

See Configuring CORS in the Apollo Router.

OpenTelemetry tracing

See Tracing in the Apollo Router.

Automatic persisted queries (APQ)

Automatic Persisted Queries (APQ) enable GraphQL clients to send a server the hash of their query string, instead of the query string itself. This can significantly reduce network usage for very large query strings.

The Apollo Router automatically supports APQ via its in-memory cache. No configuration options are supported at this time. Support for external data stores like Redis and Memcached will be supported in a future release.

For more information on APQ, including client configuration, see this article.

Plugins

You can customize the Apollo Router's behavior with plugins. Each plugin can have its own section in the configuration file with arbitrary values:

example-plugin-router.yaml
plugins:
example.plugin:
var1: "hello"
var2: 1

Environment variable expansion

You can reference environment variables directly in your YAML file in any section outside of the top-level server key. This is useful for referencing secrets without including them in the file.

Unix-style expansion is used. For example:

  • ${ENV_VAR_NAME} expands to the value of environment variable ENV_VAR_NAME.
  • ${ENV_VAR_NAME:some_default} expands to the value of environment variable ENV_VAR_NAME, or falls back to the value some_default if the environment variable is not defined.

Environment varaible expansions are valid only for YAML values, not keys:

router.yaml
example:
password: "${MY_PASSWORD}"

Reusing configuration

You can reuse parts of your configuration file in multiple places using standard YAML aliasing syntax:

router.yaml
headers:
subgraphs:
products:
- insert: &insert_custom_header
name: "custom-header"
value: "something"
reviews:
- insert: *insert_custom_header

Here, the name and value entries under &insert_custom_header are reused under *insert_custom_header.

Configuration awareness in your text editor

The Apollo Router can generate a JSON schema for config validation in your text editor. This schema helps you format the YAML file correctly and also provides content assist.

Generate the schema with the following command:

./router --schema > configuration_schema.json

After you generate the schema, configure your text editor. Here are the instructions for some commonly used editors:

Edit on GitHub
Previous
Federation version support
Next
CORS