Working with Router

Configuring GraphOS Router for Connectors


Apollo Connectors is currently in public preview .To get started, you need an Apollo account with a GraphOS Trial or Enterprise plan .

Overriding baseURL for environment-specific API hosts

When using a self-hosted router, the baseURL of a @source directive can be overridden in the router configuration file .

For example, this configuration overrides the baseURL for all @connect directives in the subgraph that reference the v1 source:

YAML
Base
1preview_connectors:
2  subgraphs:
3    example: # The name of the subgraph
4      sources:
5        v1: # Refers to @source(name: "v1")
6          override_url: 'https://api.example.com/v1/beta'
 note
If a @connect directive doesn't specify the source attribute, its URL can't be overridden.

Configuration and environment variables

You may want to use a configuration value or environment variable as part of a request. You can do this per subgraph in the router configuration by using the $config section of each connectors subgraph:

YAML
router.yaml
1preview_connectors:
2  subgraphs:
3    name_of_the_subgraph:
4      $config:
5        name_of_the_variable: value

You can then access the value using the $config variable in the schema, for example in the URL template or header of a connector:

GraphQL
1type Query {
2  something: String!
3    @connect(
4      http: {
5        GET: "https://api.example.com/products/{$config.name_of_the_variable}"
6        headers: [
7          { name: "Authorization", value: "Bearer {$config.name_of_variable_containing_token}" }
8        ]
9      }
10      selection: ""
11    )
12}

You can use $config in the same locations as $this and $args.

You can also access nested values using dot notation. For example $config.nested.value would refer to:

YAML
router.yaml
1preview_connectors:
2  subgraphs:
3    name_of_the_subgraph:
4      $config:
5        nested:
6          value: 'some value'

Router configuration also lets you inject environment variables, like this:

YAML
router.yaml
1preview_connectors:
2  subgraphs:
3    name_of_the_subgraph:
4      $config:
5        name_of_the_variable: ${env.VARIABLE_NAME}

Request Limits

The maximum number of REST API requests for each GraphQL operation can be configured in the router. This can help avoid overwhelming upstream services. Once the limit has been reached, a null value will be returned in the GraphQL result for any fields with @connect directives whose requests were not executed. Additionally, a GraphQL error will be returned in the errors array of the response. Partial data may still be returned for portions of the operation that were not affected by the limit.

The limit can be set generally in the router config YAML:

YAML
router.yaml
1preview_connectors:
2  max_requests_per_operation_per_source: 100

This will limit the number of requests made to each connector source for a given GraphQL operation. If a connector does not define a source, then this limit is applied at the connector level.

The limit can also be configured for each individual connector source:

YAML
router.yaml
1preview_connectors:
2  subgraphs:
3    subgraph_name:
4      sources:
5        source_name:
6          max_requests_per_operation: 50

Limits set on an individual source will override the general max_requests_per_operation_per_source limit.

The limit can also be configured by setting the environment variable APOLLO_CONNECTORS_MAX_REQUESTS_PER_OPERATION. Any configuration in the YAML file will override the environment variable setting.

During the preview, a few limitations apply to Connectors and Router features. Learn more .