Skip to content

Commit

Permalink
Allow schema reporting env var
Browse files Browse the repository at this point in the history
  • Loading branch information
Joshua Segaran committed Jun 4, 2020
1 parent 5519db7 commit 2d613cf
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
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 2d613cf

Please sign in to comment.