Skip to content

Commit

Permalink
Rename GraphQLService to GatewayInterface (#5296)
Browse files Browse the repository at this point in the history
`GraphQLService` was a confusing name. It's not related to
`GraphQLServiceContext` (which is the type of the argument to
`serverWillStart`) nor is it related to "service", the old name for a
graph in Studio... or "implementing service", the old name for a
subgraph... It's the type of the `gateway` option, so giving it a
gateway name seems reasonable.

But we keep exporting the old name so that we can have builds of
`@apollo/gateway` that work with both AS2 and AS3.

Fixes #4919.
  • Loading branch information
glasser committed Jun 10, 2021
1 parent db17ed1 commit e4d4bff
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
6 changes: 3 additions & 3 deletions packages/apollo-server-core/src/ApolloServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import {
Context,
ContextFunction,
PluginDefinition,
GraphQLService,
GatewayInterface,
} from './types';

import { generateSchemaHash } from './utils/schemaHash';
Expand Down Expand Up @@ -85,7 +85,7 @@ type SchemaDerivedData = {

type ServerState =
| { phase: 'initialized with schema'; schemaDerivedData: SchemaDerivedData }
| { phase: 'initialized with gateway'; gateway: GraphQLService }
| { phase: 'initialized with gateway'; gateway: GatewayInterface }
| { phase: 'starting'; barrier: Resolvable<void> }
| {
phase: 'invoking serverWillStart';
Expand Down Expand Up @@ -550,7 +550,7 @@ export class ApolloServerBase {
}

private async startGatewayAndLoadSchema(
gateway: GraphQLService,
gateway: GatewayInterface,
): Promise<GraphQLSchema> {
// Store the unsubscribe handles, which are returned from
// `onSchemaChange`, for later disposal when the server stops
Expand Down
16 changes: 8 additions & 8 deletions packages/apollo-server-core/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import type { GraphQLSchema, DocumentNode, ParseOptions } from 'graphql';
import type { IMocks } from '@graphql-tools/mock';
import type {
IResolvers,
} from '@graphql-tools/utils';
import type { IResolvers } from '@graphql-tools/utils';
import type {
ApolloConfig,
ValueOrPromise,
Expand Down Expand Up @@ -54,10 +52,8 @@ export type GraphQLServiceConfig = {
executor: GraphQLExecutor;
};

export interface GraphQLService {
load(options: {
apollo: ApolloConfig;
}): Promise<GraphQLServiceConfig>;
export interface GatewayInterface {
load(options: { apollo: ApolloConfig }): Promise<GraphQLServiceConfig>;
onSchemaChange(callback: SchemaChangeCallback): Unsubscriber;
// Note: The `TContext` typing here is not conclusively behaving as we expect:
// https://github.com/apollographql/apollo-server/pull/3811#discussion_r387381605
Expand All @@ -67,6 +63,10 @@ export interface GraphQLService {
stop(): Promise<void>;
}

// This was the name used for GatewayInterface in AS2; continue to export it so
// that older versions of `@apollo/gateway` build against AS3.
export interface GraphQLService extends GatewayInterface {}

// This configuration is shared between all integrations and should include
// fields that are not specific to a single integration
export interface Config extends BaseConfig {
Expand All @@ -81,7 +81,7 @@ export interface Config extends BaseConfig {
mockEntireSchema?: boolean;
plugins?: PluginDefinition[];
persistedQueries?: PersistedQueryOptions | false;
gateway?: GraphQLService;
gateway?: GatewayInterface;
experimental_approximateDocumentStoreMiB?: number;
stopOnTerminationSignals?: boolean;
apollo?: ApolloConfigInput;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import {
Config,
ApolloServerBase,
PluginDefinition,
GraphQLService,
GatewayInterface,
GraphQLExecutor,
GraphQLServiceConfig,
ApolloServerPluginInlineTrace,
Expand Down Expand Up @@ -145,7 +145,7 @@ const makeGatewayMock = ({
triggerSchemaChange: null as ((newSchema: GraphQLSchema) => void) | null,
};

const mockedGateway: GraphQLService = {
const mockedGateway: GatewayInterface = {
executor,
load: async (options) => {
optionsSpy(options);
Expand Down

0 comments on commit e4d4bff

Please sign in to comment.