Schema registration via schema reporting
Schema reporting enables your GraphQL server to register its latest schema with Apollo every time it starts up. To use this feature, your server needs to support the schema reporting protocol. This protocol is supported by Apollo Server, and other GraphQL servers can implement support.
Schema reporting does not currently support graphs that use Apollo Federation. If you have a federated graph, instead see Setting up managed federation.
⚠️ Important: With schema reporting, your sever publishes schema updates at runtime. This can lead to non-deterministic results. We recommend instead using the Rover CLI in a CI/CD pipeline for isolated and reproducible schema checks and publishes.
For more information on staging and releasing schema updates, see Change management in Apollo Federation
Schema reporting is available in Apollo Server version 2.15 and later. To enable it:
Obtain an API key for your graph:
Set this API key as the value of the
APOLLO_KEYenvironment variable in your server's environment, and also set the
APOLLO_SCHEMA_REPORTINGenvironment variable to
If you're using the
dotenvlibrary, you can add these definitions to the
.envfile in your project's root directory, like so:.envAPOLLO_KEY=YOUR_KEY_HEREAPOLLO_GRAPH_ID=your-graph-idAPOLLO_SCHEMA_REPORTING=true
Important: If you use a
.envfile, do not commit it to version control. Always use
.gitignoreor a similar method to omit files that include secret credentials.
You can alternatively provide these values to Apollo Server via the
apolloconstructor option, but again, do not add secret credentials to your application source.
Now every time your server finishes starting up, it waits a random amount of time between zero and ten seconds before automatically registering its schema (you can customize this time range).
Your server can register its schema to a particular variant of your graph. Each of your server's environments (development, staging, production, etc.) should register to a different variant.
To do so with Apollo Server, set the
APOLLO_GRAPH_VARIANT environment variable in each server environment:
If you don't specify a variant, Apollo Server reports its schema to the default variant (named
The schema reporting protocol accepts optional values that help both you and Apollo associate each request with a particular server instance and platform. This in turn helps with diagnosing issues and improving performance.
To provide these values to Apollo Server, set the following environment variables in your server's environment:
|An identifier for the current running version of your server, such as the SHA of its associated Git commit. We plan to display this value in Apollo Studio to help you segment metrics.|
|An ID that's unique for each running instance of your server. This value should persist across an instance's restarts. For example, in a Kubernetes cluster, you can use the server's pod name.|
|The infrastructure environment that your server is running in (|
Apollo Server supports schema reporting via a plugin called
ApolloServerPluginSchemaReporting. When you set the
APOLLO_SCHEMA_REPORTING environment variable to
true, Apollo Server automatically installs this plugin with its default configuration.
If you need to configure the plugin further, you can explicitly install the plugin in your server. For example, you can tweak the amount of time that Apollo Server waits on startup before attempting to register its schema, or you can override the actual schema string that is registered. For details, see the schema reporting plugin reference.
Any GraphQL server can (and is encouraged to!) support automatic schema registration by implementing the Schema reporting protocol.
Currently, we are not aware of GraphQL server libraries besides Apollo Server that implement the schema reporting protocol. If you add support to an open-source library, please let us know at firstname.lastname@example.org!
Whenever you perform a rolling deployment of a schema update, different active instances of your server might temporarily report different schemas to Apollo. If this occurs, Apollo uses the following algorithm to choose which schema to register:
Using this algorithm, your updated schema is registered within a few minutes after your rolling deployment completes.