Skip to content

Commit

Permalink
Pass along the schema derived data computed during SchemaManager cons…
Browse files Browse the repository at this point in the history
…truction to start()
  • Loading branch information
sachindshinde committed Sep 27, 2021
1 parent 09953f9 commit 8850ed7
Showing 1 changed file with 15 additions and 9 deletions.
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

0 comments on commit 8850ed7

Please sign in to comment.