Join us for GraphQL Summit, October 10-12 in San Diego. Super Early Bird registration ends soon!
Try Apollo Studio

Setting up managed federation

This article describes how to set up Apollo Studio for a graph that uses Apollo Federation.

As with all changes, you should first set up managed federation in a non-production environment, such as staging. To support this, you can use variants, which are distinct versions of the same graph for different environments.

1. Get started

If you haven't yet, complete the first two steps from the Apollo Studio getting started guide:

  1. Create your account
  2. Create your first graph

In the Register your schema step, make sure you follow the instructions for a GraphQL server that uses Apollo Federation.

2. Register all subgraph schemas

In a federated architecture, each of your graph's subgraphs uses the Rover CLI to register its schema with Apollo:

rover subgraph publish
rover subgraph publish
rover subgraph publish
Products subgraph
Reviews subgraph
Inventory subgraph
Apollo Schema Registry

If you haven't yet:

Then, do the following for each of your subgraphs:

  1. Obtain the following values, which are required for the rover subgraph publish command:

    • The name that uniquely identifies the subgraph within your graph (e.g., products).
    • The URL that your gateway will use to communicate with the subgraph (e.g., http://products-graphql.svc.cluster.local:4001/).
  2. Run the rover subgraph publish command, providing it your subgraph's schema in one of the ways shown:

    # Provide a local .graphql file path
    rover subgraph publish my-graph@my-variant --name products --routing-url http://products-graphql.svc.cluster.local:4001/ --schema ./schema.graphql
    # Provide an introspection result via stdin
    rover subgraph introspect http://localhost:4000 | rover subgraph publish my-graph@my-variant --name products --routing-url http://products-graphql.svc.cluster.local:4001/ --schema -

As you register your subgraph schemas, the schema registry attempts to compose their latest versions into a single supergraph schema. Whenever composition succeeds, your gateway can fetch the latest supergraph schema from the registry.

You can also manually fetch your latest supergraph schema with the rover supergraph fetch command, or retrieve it from your graph's Schema > SDL tab in Apollo Studio.

3. Modify your Apollo Router startup (if necessary)

If you've already set up Apollo Federation without Apollo Studio, you're probably passing a --supergraph (or -s) flag in the command (e.g., in container startup scripts) you use to start the Apollo Router:

router --config ./router.yaml --supergraph ./your-local-supergraph.graphql

Your configuration file might use a different name, but the --supergraph option is specific to non-managed federation, in which supergraph schema composition is performed via the Rover CLI and provided as a file.

With managed federation, composition is instead performed by Apollo, and the router regularly polls Apollo for an updated schema. This enables you to add, remove, and modify your subgraphs via Apollo Studio's registry without needing to restart your router.

When starting the Apollo Router and retrieving the schema from the Apollo Studio registry, remove the --supergraph (or -s) argument from your Apollo Router startup command, leaving the --config argument if it was already provided:

router --config ./router.yaml

4. Connect the router to Studio

Your router uses a graph API key to identify itself to Studio.

After obtaining your graph API key, you set two environment variables in your environment when starting your router:


The --config argument may be present if you were previously passing the operational configuration file to the router and the configuration may use a different name.

The APOLLO_GRAPH_REF environment variable tells the Apollo Router which variant of which graph to use (for example, my-graph-id@production). You can find your variant's graph ref at the very top of its README page in Studio.

5. Start the Router

You can now deploy your modified router to begin fetching your federated schema from Studio instead of directly from your subgraphs.

On startup, your router will use its API key to fetch its federation config from Apollo. It can then begin executing operations across your subgraphs.

Edit on GitHub
Client awareness