Skip to content

Commit

Permalink
Merge pull request #4206 from apollographql/jsegaran/schema_report_en…
Browse files Browse the repository at this point in the history
…v_var

Allow schema reporting via environment variable
  • Loading branch information
jsegaran authored Jun 10, 2020
2 parents fd79e65 + 4c41abc commit 6b342ca
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 10 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ The version headers in this history reflect the versions of Apollo Server itself
- [__CHANGELOG for `@apollo/gateway`__](https://github.com/apollographql/apollo-server/blob/master/packages/apollo-gateway/CHANGELOG.md)
- [__CHANGELOG for `@apollo/federation`__](https://github.com/apollographql/apollo-server/blob/master/packages/apollo-federation/CHANGELOG.md)

### vNext

- `apollo-engine-reporting`: Add environment variable `APOLLO_SCHEMA_REPORTING` that can enable schema reporting. If `experimental__schemaReporting` is set it will override the environment variables.

### v2.14.3

- This release only includes patch updates to dependencies.
Expand Down
16 changes: 7 additions & 9 deletions packages/apollo-engine-reporting/src/__tests__/plugin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,13 @@ describe('schema reporting', () => {

it('starts reporting if enabled', async () => {
const pluginInstance = plugin(
{
experimental_schemaReporting: true,
},
{},
addTrace,
{
startSchemaReporting,
executableSchemaIdGenerator,
},
schemaReport: true,
}
);

await pluginTestHarness({
Expand Down Expand Up @@ -97,13 +96,13 @@ describe('schema reporting', () => {
it('uses the override schema', async () => {
const pluginInstance = plugin(
{
experimental_schemaReporting: true,
experimental_overrideReportedSchema: typeDefs,
},
addTrace,
{
startSchemaReporting,
executableSchemaIdGenerator,
schemaReport: true,
},
);

Expand Down Expand Up @@ -145,14 +144,13 @@ describe('schema reporting', () => {

it('uses the same executable schema id for metric reporting', async () => {
const pluginInstance = plugin(
{
experimental_schemaReporting: true,
},
{},
addTrace,
{
startSchemaReporting,
executableSchemaIdGenerator,
},
schemaReport: true,
}
);

await pluginTestHarness({
Expand Down
9 changes: 9 additions & 0 deletions packages/apollo-engine-reporting/src/agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,7 @@ export class EngineReportingAgent<TContext = any> {
};

private readonly tracesEndpointUrl: string;
private readonly schemaReport: boolean;

public constructor(options: EngineReportingOptions<TContext> = {}) {
this.options = options;
Expand All @@ -407,6 +408,13 @@ export class EngineReportingAgent<TContext = any> {
);
}


if (options.experimental_schemaReporting !== undefined) {
this.schemaReport = options.experimental_schemaReporting;
} else {
this.schemaReport = process.env.APOLLO_SCHEMA_REPORTING === "true"
}

// Since calculating the signature for Engine reporting is potentially an
// expensive operation, we'll cache the signatures we generate and re-use
// them based on repeated traces for the same `queryHash`.
Expand Down Expand Up @@ -469,6 +477,7 @@ export class EngineReportingAgent<TContext = any> {
return plugin(this.options, this.addTrace.bind(this), {
startSchemaReporting: this.startSchemaReporting.bind(this),
executableSchemaIdGenerator: this.executableSchemaIdGenerator.bind(this),
schemaReport: this.schemaReport,
});
}

Expand Down
4 changes: 3 additions & 1 deletion packages/apollo-engine-reporting/src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export const plugin = <TContext>(
{
startSchemaReporting,
executableSchemaIdGenerator,
schemaReport,
}: {
startSchemaReporting: ({
executableSchema,
Expand All @@ -43,6 +44,7 @@ export const plugin = <TContext>(
executableSchemaId: string;
}) => void;
executableSchemaIdGenerator: (schema: string | GraphQLSchema) => string;
schemaReport: boolean;
},
): ApolloServerPlugin<TContext> => {
/**
Expand All @@ -57,7 +59,7 @@ export const plugin = <TContext>(

return {
serverWillStart: function({ schema }) {
if (!options.experimental_schemaReporting) return;
if (!schemaReport) return;
startSchemaReporting({
executableSchema:
options.experimental_overrideReportedSchema || printSchema(schema),
Expand Down

0 comments on commit 6b342ca

Please sign in to comment.