Join us from October 8-10 in New York City to learn the latest tips, trends, and news about GraphQL Federation and API platform engineering.Join us for GraphQL Summit 2024 in NYC
Docs
Start for Free

Publishing Schemas to GraphOS

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


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

This page covers how to publish different kinds of schemas using the . 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 .

Publish subgraph schemas

Every in GraphOS includes one or more subgraphs. These are the individual -powered microservices in your organization.

You individually publish each 's schema to Apollo with rover subgraph publish:

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

rover subgraph publish
rover subgraph publish
rover subgraph publish
Products
subgraph
Reviews
subgraph
Inventory
subgraph
GraphOS

To publish a to Apollo:

  1. Identify the name of the subgraph you're publishing to. You can view the names of your existing subgraphs from your '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 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:

    # 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 for your router:

(Composition succeeds)
Subgraph
schema
A
Subgraph
schema
B
Subgraph
schema
C
🛠
Composition
Supergraph schema
(A + B + C + routing machinery)

If this succeeds, your router is updated with the result. This enables clients to any newly added , 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 .

Publish monograph schemas

NOTE

These instructions apply only to monographs, which are not recommended.

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

    • Use a .gql or .graphql file saved on your local machine, or
    • Perform an 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:

    # 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 you provide rover graph publish is a graph ref, a string that specifies a particular variant of a particular graph in GraphOS.

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:

version: 2
jobs:
build:
docker:
- image: circleci/node:8
steps:
- checkout
- run: npm install
- run:
name: Install Rover
command: |
# Download and install Rover
# This is pinned to a specific version for predictability in CI
curl -sSL https://rover.apollo.dev/nix/v0.8.1 | sh
# This allows the PATH changes to persist to the next `run` step
echo 'export PATH=$HOME/.rover/bin:$PATH' >> $BASH_ENV
# Start the GraphQL server. If a different command is used to
# start the server, use it in place of `npm start` here.
- run:
name: Starting server
command: npm start
background: true
# make sure the server has enough time to start up before running
# commands against it
- run: sleep 5
# When running on the 'main' branch, push the latest version
# of the schema to GraphOS.
- run: |
if [ "${CIRCLE_BRANCH}" == "main" ]; then
rover subgraph publish my-graph@my-variant \
--schema ./schema.graphql \
--name locations \
--routing-url https://products.example.com
fi
Previous
Implement Proposals
Next
Launches
Rate articleRateEdit on GitHubEditForumsDiscord

© 2024 Apollo Graph Inc., d/b/a Apollo GraphQL.

Privacy Policy

Company