Launch GraphOS Studio

API Reference: Schema reporting plugin


Using the plugin

This article documents the options for the ApolloServerPluginSchemaReporting plugin, which you can import from @apollo/server/plugin/schemaReporting.

This plugin enables your GraphQL server to register its latest with the Apollo every time it starts up. Full details on reporting can be found in the Apollo Studio docs.

Schema reporting does not currently support graphs that use Apollo Federation. This plugin will not work if your graph is a federated or a composed federated graph running in a gateway. If you have a federated graph, you will need to register your via the CLI. See Setting up managed federation for more details.

In order to use this plugin, you must configure your server with a graph API key, either with the APOLLO_KEY environment or by passing it directly to your ApolloServer constructor (e.g., new ApolloServer({apollo: {key: KEY}})). This is the same way you configure usage reporting.

You must explicitly enable reporting. If you want to turn on reporting with its default configuration, you can set the APOLLO_SCHEMA_REPORTING environment to true.

If you want to configure reporting (or prefer your setup to be via code rather than using environment s), import the ApolloServerPluginSchemaReporting plugin and pass it to the ApolloServer constructor:

import { ApolloServer } from '@apollo/server';
import { ApolloServerPluginSchemaReporting } from '@apollo/server/plugin/schemaReporting';
const server = new ApolloServer({
typeDefs,
resolvers,
plugins: [ApolloServerPluginSchemaReporting()],
});
import { ApolloServer } from '@apollo/server';
import { ApolloServerPluginSchemaReporting } from '@apollo/server/plugin/schemaReporting';
const server = new ApolloServer({
typeDefs,
resolvers,
plugins: [ApolloServerPluginSchemaReporting()],
});

Options

Name /
Type
Description
initialDelayMaxMs

number

The reporter waits before starting reporting. By default, the report waits some random amount of time between 0 and 10 seconds. A longer interval leads to more staggered starts which means it is less likely multiple servers will get asked to upload the same .

If this server runs in lambda or in other constrained environments it would be useful to decrease the reporting max wait time to be less than default.

This number will be the max for the range in ms that the reporter will wait before starting to report.

overrideReportedSchema

string

Override the reported that is reported to the Apollo . This does not go through any normalizations and the string is directly sent to the Apollo . This can be useful for comments or other ordering and whitespace changes that get stripped when generating a GraphQLSchema.

If you pass this option to this plugin, you should explicitly configure ApolloServerPluginUsageReporting and pass the same value to its overrideReportedSchema option. This ensures that the ID associated with requests reported by the usage reporting plugin matches the ID that this plugin reports. For example:

new ApolloServer({
plugins: [
ApolloServerPluginSchemaReporting({
overrideReportedSchema: schema
}),
ApolloServerPluginUsageReporting({
overrideReportedSchema: schema
}),
],
// ...
})
endpointUrl

string

The URL to use for reporting s. Primarily for testing and internal Apollo use.

fetcher

typeof fetch

Specifies which Fetch API function implementation to use when reporting s.

Disabling the plugin

The reporting plugin is only automatically installed if the APOLLO_SCHEMA_REPORTING is set to true, so the easiest way to disable the plugin is to avoid setting that environment (and to not explicitly install ApolloServerPluginSchemaReporting). However, if you'd like to ensure that the reporting plugin is not installed in your server (perhaps for a test that might run with arbitrary environment s set), you can disable reporting by installing the ApolloServerPluginSchemaReportingDisabled plugin, like so:

import { ApolloServer } from '@apollo/server';
import { ApolloServerPluginSchemaReportingDisabled } from '@apollo/server/plugin/disabled';
const server = new ApolloServer({
typeDefs,
resolvers,
plugins: [ApolloServerPluginSchemaReportingDisabled()],
});
import { ApolloServer } from '@apollo/server';
import { ApolloServerPluginSchemaReportingDisabled } from '@apollo/server/plugin/disabled';
const server = new ApolloServer({
typeDefs,
resolvers,
plugins: [ApolloServerPluginSchemaReportingDisabled()],
});