Join us for GraphQL Summit, October 10-12 in San Diego. Use promo code ODYSSEY for $400 off your pass.
Launch GraphOS Studio

Setting up managed federation

This article describes how to connect your to Apollo GraphOS to enable managed federation features.

As with all changes, you should first set up managed federation in a non-production environment, such as staging. To support this, you can create multiple variants of your in Studio. Each represents a distinct version of the same graph for different environments.

1. Get started

First, complete the Set up Apollo tools step from this tutorial, including:

  • Creating an Apollo account
  • Creating a graph in Studio
  • Installing and authenticating the CLI

Then return here.

2. Publish all subgraph schemas

In a architecture, each of your subgraphs uses the CLI to publish its to :

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

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 within your graph (e.g., products).
    • The URL that your will use to communicate with the (e.g., http://products-graphql.svc.cluster.local:4001/).
  2. Run the rover subgraph publish command, providing it your 's 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 s, the attempts to compose their latest versions into a single supergraph schema. Whenever composition succeeds, your managed can fetch the latest from .

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

3. Modify your router's startup command

If you've already set up Apollo Federation without connecting your to , you're probably passing the --supergraph (or -s) option to the Apollo 's startup command:

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

The --supergraph option is specific to non-managed federation, in which composition is performed via the CLI and provided via a file path.

Remove the --supergraph option (but leave --config if it's present):

./router --config ./router.yaml

With managed federation, composition is instead performed by GraphOS, and the regularly polls for an updated . This enables you to add, remove, and modify your s without needing to restart your .

4. Connect your router to GraphOS

Like your s, your uses a graph API key to identify itself to .

After obtaining your graph API key, you set the following environment s in your 's environment:

  • APOLLO_KEY (set this to your graph API key)
    • This tells the which of which graph to use (for example, docs-example-graph@production). You can find your 's graph ref at the very top of its README page in Studio.

5. Deploy the modified router

You can now deploy your modified , which will fetch its from on startup. It can then begin executing s across your s.

Edit on GitHubEditForumsDiscord