Publishing Schemas to GraphOS

Use the Rover CLI to publish schemas as part of your CI/CD pipeline


Whenever you make changes to a graph's schema, you should publish those changes to Apollo GraphOS using the Rover CLI or the Platform API . Doing so ensures that GraphOS always has an up-to-date understanding of your graph.

This page covers how to publish different kinds of schemas using the Rover CLI. Consult the Platform API reference to learn how to use the API for publication.

💡 tip
Incorporate schema proposals into schema checks to ensure your organization only publishes approved changes. Learn more.

Prerequisites

  1. Install the Rover CLI .

  2. Authenticate Rover with GraphOS.

Publish monograph schemas

These instructions apply only to monograph. Skip to publishing subgraph schemas if you're using a supergraph.

  1. Decide how you'll provide your server's schema to Rover. You can either:

    • Use a .gql or .graphql file saved on your local machine, or

    • Perform an introspection query on your running server to fetch the schema

  2. Run the rover graph publish command, providing your schema in one of the ways shown:

    Bash
    
    # Provide a local .graphql file path
    rover graph publish my-graph@my-variant --schema ./schema.graphql
    
    # Provide an introspection result via stdin
    rover graph introspect http://localhost:4000 | rover graph publish my-graph@my-variant --schema -

    As shown, the first positional argument you provide rover graph publish is a graph ref , a string that specifies a particular variant of a particular graph in GraphOS.

Publish subgraph schemas

When working with supergraphs, you individually publish each subgraph's schema to GraphOS with rover subgraph publish:

Bash
Example
rover subgraph publish --schema ./products.graphql --name products docs-example-graph@current --routing-url https://products.example.com

To publish a subgraph schema to GraphOS:

  1. Identify the name of the subgraph you're publishing to. You can view the names of your existing subgraphs from your variant's Subgraphs page in GraphOS Studio .

  2. If you're publishing a subgraph for the first time, also obtain the routing URL of that subgraph. This is the URL that your router will use to communicate with the subgraph.

    • If GraphOS already knows your subgraph's routing URL, you don't need to provide this value unless you're changing it.

  3. Run the rover subgraph publish command and provide it your subgraph's schema in one of the ways shown:

    Bash
    
    # Provide a local .graphql file path
    rover subgraph publish my-graph@my-variant --name locations --routing-url https://flyby-locations-sub.herokuapp.com/ --schema ./schema.graphql
    
    # Provide an introspection result via stdin
    rover subgraph introspect http://localhost:4000 | rover subgraph publish my-graph@my-variant --name locations --routing-url https://flyby-locations-sub.herokuapp.com/ --schema -

Whenever you publish a subgraph schema, GraphOS attempts to compose all latest versions of your subgraph schemas into a single supergraph schema for your router:

If this composition succeeds, your router is updated with the result. This enables clients to query any newly added fields, and it prevents them from querying any removed fields.

You can manually fetch your router's latest supergraph schema with the rover supergraph fetch command, or retrieve it from your supergraph's Schema > SDL page in GraphOS Studio.

Publish with continuous delivery

To get the most out of GraphOS, you should publish each update to any production schema as soon as it occurs. Consequently, schema publishing should be part of your continuous delivery pipeline.

Here's a sample continuous delivery configuration for schema publishing in CircleCI:

YAML
1version: 2
2
3jobs:
4  build:
5    docker:
6      - image: circleci/node:8
7
8    steps:
9      - checkout
10
11      - run: npm install
12
13      - run:
14          name: Install Rover
15          # highlight-start
16          command: |
17            # Download and install Rover
18            # This is pinned to a specific version for predictability in CI
19            curl -sSL https://rover.apollo.dev/nix/v0.8.1 | sh
20
21            # This allows the PATH changes to persist to the next `run` step
22            echo 'export PATH=$HOME/.rover/bin:$PATH' >> $BASH_ENV
23          # highlight-end
24
25      # Start the GraphQL server.  If a different command is used to
26      # start the server, use it in place of `npm start` here.
27      - run:
28          name: Starting server
29          command: npm start
30          background: true
31
32      # make sure the server has enough time to start up before running
33      # commands against it
34      - run: sleep 5
35
36      # highlight-start
37      # When running on the 'main' branch, push the latest version
38      # of the schema to GraphOS.
39      - run: |
40          if [ "${CIRCLE_BRANCH}" == "main" ]; then
41            rover subgraph publish my-graph@my-variant \
42              --schema ./schema.graphql \
43              --name locations \
44              --routing-url https://products.example.com
45          fi
46      # highlight-end