Skip to content

Commit

Permalink
fix(gateway): Make protected fields and methods private (except `…
Browse files Browse the repository at this point in the history
…loadServiceDefinitions`) (#539)
  • Loading branch information
trevor-scheer committed Mar 9, 2021
1 parent 37424fc commit 56349fc
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 15 deletions.
2 changes: 2 additions & 0 deletions gateway-js/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
30 changes: 15 additions & 15 deletions gateway-js/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,10 @@ type GatewayState =
| { phase: 'polling'; pollingDonePromise: Promise<void> };
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<QueryPlan>;
private queryPlanStore: InMemoryLRUCache<QueryPlan>;
private apolloConfig?: ApolloConfig;
private onSchemaChangeListeners = new Set<SchemaChangeCallback>();
private serviceDefinitions: ServiceDefinition[] = [];
Expand All @@ -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 = {
Expand Down Expand Up @@ -362,7 +362,7 @@ export class ApolloGateway implements GraphQLService {
return isManagedConfig(this.config) || this.experimental_pollInterval;
}

protected async updateComposition(): Promise<void> {
private async updateComposition(): Promise<void> {
let result: Await<ReturnType<Experimental_UpdateServiceDefinitions>>;
this.logger.debug('Checking service definitions...');
try {
Expand Down Expand Up @@ -497,7 +497,7 @@ export class ApolloGateway implements GraphQLService {
);
}

protected createSchema(
private createSchema(
input: { serviceList: ServiceDefinition[] } | { csdl: string },
) {
if ('serviceList' in input) {
Expand All @@ -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}`)
Expand Down Expand Up @@ -550,7 +550,7 @@ export class ApolloGateway implements GraphQLService {
}
}

protected serviceListFromCsdl() {
private serviceListFromCsdl() {
const serviceList: Omit<ServiceDefinition, 'typeDefs'>[] = [];

visit(this.parsedCsdl!, {
Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -908,7 +908,7 @@ export class ApolloGateway implements GraphQLService {
return response;
};

protected validateIncomingRequest<TContext>(
private validateIncomingRequest<TContext>(
requestContext: GraphQLRequestContextExecutionDidStart<TContext>,
operationContext: OperationContext,
) {
Expand Down

0 comments on commit 56349fc

Please sign in to comment.