Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

apollo-server-core: Stop computing schema-derived data twice for non-gateway modes of operation #5757

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ The version headers in this history reflect the versions of Apollo Server itself

- `apollo-server-koa`: The peer dependency on `koa` (added in v3.0.0) should be a `^` range dependency rather than depending on exactly one version, and it should not be automatically increased when new versions of `koa` are released. [PR #5759](https://github.com/apollographql/apollo-server/pull/5759)
- `apollo-server-fastify`: Export `ApolloServerFastifyConfig` and `FastifyContext` TypeScript types. [PR #5743](https://github.com/apollographql/apollo-server/pull/5743)
- `apollo-server-core`: Only generate the schema hash once on startup rather than twice. [PR #5757](https://github.com/apollographql/apollo-server/pull/5757)

## v3.3.0

Expand Down
24 changes: 15 additions & 9 deletions packages/apollo-server-core/src/utils/schemaManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export class SchemaManager {
| {
readonly mode: 'schema';
readonly apiSchema: GraphQLSchema;
readonly schemaDerivedData: SchemaDerivedData;
};

constructor(
Expand All @@ -69,10 +70,11 @@ export class SchemaManager {
this.modeSpecificState = {
mode: 'schema',
apiSchema: options.apiSchema,
// The caller of the constructor expects us to fail early if the schema
// given is invalid/has errors, so we call the provider here. We also
// pass the result to start(), as the provider can be expensive to call.
schemaDerivedData: options.schemaDerivedDataProvider(options.apiSchema),
};
// The caller of the constructor expects us to fail early if the schema
// given is invalid/has errors, so we call the provider here.
options.schemaDerivedDataProvider(options.apiSchema);
}
}

Expand Down Expand Up @@ -119,9 +121,12 @@ export class SchemaManager {
}
return config.executor;
} else {
this.processSchemaLoadOrUpdateEvent({
apiSchema: this.modeSpecificState.apiSchema,
});
this.processSchemaLoadOrUpdateEvent(
{
apiSchema: this.modeSpecificState.apiSchema,
},
this.modeSpecificState.schemaDerivedData,
);
return null;
}
}
Expand Down Expand Up @@ -209,11 +214,12 @@ export class SchemaManager {

private processSchemaLoadOrUpdateEvent(
schemaContext: GraphQLSchemaContext,
schemaDerivedData?: SchemaDerivedData,
): void {
if (!this.isStopped) {
this.schemaDerivedData = this.schemaDerivedDataProvider(
schemaContext.apiSchema,
);
this.schemaDerivedData =
schemaDerivedData ??
this.schemaDerivedDataProvider(schemaContext.apiSchema);
this.schemaContext = schemaContext;
this.onSchemaLoadOrUpdateListeners.forEach((listener) => {
try {
Expand Down