From 56349fc2f0eeea2d8288906cf7fd73953fa18f2f Mon Sep 17 00:00:00 2001 From: Trevor Scheer Date: Tue, 9 Mar 2021 13:12:50 -0800 Subject: [PATCH] fix(gateway): Make `protected` fields and methods `private` (except `loadServiceDefinitions`) (#539) --- gateway-js/CHANGELOG.md | 2 ++ gateway-js/src/index.ts | 30 +++++++++++++++--------------- 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/gateway-js/CHANGELOG.md b/gateway-js/CHANGELOG.md index 90b74cac5..536adeed3 100644 --- a/gateway-js/CHANGELOG.md +++ b/gateway-js/CHANGELOG.md @@ -4,6 +4,8 @@ > The changes noted within this `vNEXT` section have not been released yet. New PRs and commits which introduce changes should include an entry in this `vNEXT` section as part of their development. When a release is being prepared, a new header will be (manually) created below and the appropriate changes within that release will be moved into the new section. +- __BREAKING__: Make all `protected` gateway fields and methods `private` (except `loadServiceDefinitions`). If you currently depend on the ability to override any of these currently `protected` members of `ApolloGateway` please let us know. For additional context on why `loadServiceDefinitions` remains `protected` (for now) please read the associated PR description and linked issue. [PR #539](https://github.com/apollographql/federation/pull/539) + ## v0.23.2 - Only changes in the similarly versioned `@apollo/federation` package. diff --git a/gateway-js/src/index.ts b/gateway-js/src/index.ts index 183d4ea16..25a89d599 100644 --- a/gateway-js/src/index.ts +++ b/gateway-js/src/index.ts @@ -135,10 +135,10 @@ type GatewayState = | { phase: 'polling'; pollingDonePromise: Promise }; export class ApolloGateway implements GraphQLService { public schema?: GraphQLSchema; - protected serviceMap: DataSourceMap = Object.create(null); - protected config: GatewayConfig; + private serviceMap: DataSourceMap = Object.create(null); + private config: GatewayConfig; private logger: Logger; - protected queryPlanStore: InMemoryLRUCache; + private queryPlanStore: InMemoryLRUCache; private apolloConfig?: ApolloConfig; private onSchemaChangeListeners = new Set(); private serviceDefinitions: ServiceDefinition[] = []; @@ -154,19 +154,19 @@ export class ApolloGateway implements GraphQLService { // Observe query plan, service info, and operation info prior to execution. // The information made available here will give insight into the resulting // query plan and the inputs that generated it. - protected experimental_didResolveQueryPlan?: Experimental_DidResolveQueryPlanCallback; + private experimental_didResolveQueryPlan?: Experimental_DidResolveQueryPlanCallback; // Observe composition failures and the ServiceList that caused them. This // enables reporting any issues that occur during composition. Implementors // will be interested in addressing these immediately. - protected experimental_didFailComposition?: Experimental_DidFailCompositionCallback; + private experimental_didFailComposition?: Experimental_DidFailCompositionCallback; // Used to communicated composition changes, and what definitions caused // those updates - protected experimental_didUpdateComposition?: Experimental_DidUpdateCompositionCallback; + private experimental_didUpdateComposition?: Experimental_DidUpdateCompositionCallback; // Used for overriding the default service list fetcher. This should return // an array of ServiceDefinition. *This function must be awaited.* - protected updateServiceDefinitions: Experimental_UpdateServiceDefinitions; + private updateServiceDefinitions: Experimental_UpdateServiceDefinitions; // how often service defs should be loaded/updated (in ms) - protected experimental_pollInterval?: number; + private experimental_pollInterval?: number; constructor(config?: GatewayConfig) { this.config = { @@ -362,7 +362,7 @@ export class ApolloGateway implements GraphQLService { return isManagedConfig(this.config) || this.experimental_pollInterval; } - protected async updateComposition(): Promise { + private async updateComposition(): Promise { let result: Await>; this.logger.debug('Checking service definitions...'); try { @@ -497,7 +497,7 @@ export class ApolloGateway implements GraphQLService { ); } - protected createSchema( + private createSchema( input: { serviceList: ServiceDefinition[] } | { csdl: string }, ) { if ('serviceList' in input) { @@ -507,7 +507,7 @@ export class ApolloGateway implements GraphQLService { } } - protected createSchemaFromServiceList(serviceList: ServiceDefinition[]) { + private createSchemaFromServiceList(serviceList: ServiceDefinition[]) { this.logger.debug( `Composing schema from service list: \n${serviceList .map(({ name, url }) => ` ${url || 'local'}: ${name}`) @@ -550,7 +550,7 @@ export class ApolloGateway implements GraphQLService { } } - protected serviceListFromCsdl() { + private serviceListFromCsdl() { const serviceList: Omit[] = []; visit(this.parsedCsdl!, { @@ -581,7 +581,7 @@ export class ApolloGateway implements GraphQLService { return serviceList; } - protected createSchemaFromCsdl(csdl: string) { + private createSchemaFromCsdl(csdl: string) { this.parsedCsdl = parse(csdl); const serviceList = this.serviceListFromCsdl(); @@ -712,7 +712,7 @@ export class ApolloGateway implements GraphQLService { }); } - protected createServices(services: ServiceEndpointDefinition[]) { + private createServices(services: ServiceEndpointDefinition[]) { for (const serviceDef of services) { this.createAndCacheDataSource(serviceDef); } @@ -908,7 +908,7 @@ export class ApolloGateway implements GraphQLService { return response; }; - protected validateIncomingRequest( + private validateIncomingRequest( requestContext: GraphQLRequestContextExecutionDidStart, operationContext: OperationContext, ) {