Runtime Configuration Overview

Configure GraphOS Router to customize Apollo Connectors


In this guide, you'll learn how to configure the GraphOS Router for Apollo Connectors by configuring connectors and other options in your router's configuration.

Configuration

Configuring a self-hosted router for Connectors requires setting options in the router's YAML configuration file. When using Rover, you can call rover dev to start a router locally and use its --router-config option to pass your configuration file. For example:

terminal
APOLLO_KEY=... \
APOLLO_GRAPH_REF=... \
APOLLO_ROVER_DEV_ROUTER_VERSION=2.0.0 \
rover dev --supergraph-config supergraph.yaml
--router-config router.yaml

Connectors configuration are nested under the connectors key. Some configurations are applicable globally to all Connectors, some are applicable to specific Connector sources, and some can be configured for both. For example, you can apply request limits both globally across all Connectors and on specific Connector sources.

YAML
router.yaml
connectors:
  # This applies globally to all Connectors
  max_requests_per_operation_per_source: 100
  # This applies to Connectors with the "v1" source in the "example" subgraph
  sources:
    example.v1:
      max_requests_per_operation: 50

To specify a source, you must include the subgraph name and source name, separated by a .—for example, subgraph_name.connector_name.

note
The example configurations on this page use the configuration format and names in the General Availability release. If you are using a preview release, see the section on migrating your configuration.

To learn more about other router configurations, go to the router configuration reference.

Accessing router configuration in Connectors

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

YAML
router.yaml
connectors:
  sources:
    example.v1:
      # These configurations apply to Connectors with the "v1" source in the "example" subgraph
      $config:
        my.config.value: true
    example.v2:
      # These configurations apply to Connectors with the "v2" source in the "example" subgraph
      $config:
        another.config.value: true # Applies to the "v2" source

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
type Query {
  something: String!
    @connect(
      http: {
        GET: "https://api.example.com/products/{$config.name_of_the_variable}"
        headers: [{ name: "Authorization", value: "Bearer {$config.name_of_variable_containing_token}" }]
      }
      selection: ""
    )
}

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

YAML
router.yaml
connectors:
  sources:
    example.v1:
      $config:
        nested:
          value: "some value"

Router configuration also lets you inject environment variables like this:

YAML
router.yaml
connectors:
  sources:
    example.v1:
      $config:
        name_of_the_variable: ${env.VARIABLE_NAME}

Next steps

Feedback

Ask Community

OSZAR »