Skip to content

Commit

Permalink
Move to {gateway: createGateway} API
Browse files Browse the repository at this point in the history
  • Loading branch information
Jackson Kearl committed Jun 25, 2019
1 parent 6df6f00 commit 3c9bdc5
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 11 deletions.
15 changes: 4 additions & 11 deletions packages/apollo-gateway/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {
GraphQLExecutor,
GraphQLExecutionResult,
GraphQLRequestContext,
GraphQLService,
} from 'apollo-server-core';
import { InMemoryLRUCache } from 'apollo-server-caching';
import { isObjectType, isIntrospectionType, GraphQLSchema } from 'graphql';
Expand All @@ -24,12 +24,6 @@ import { serializeQueryPlan, QueryPlan } from './QueryPlan';
import { GraphQLDataSource } from './datasources/types';
import { RemoteGraphQLDataSource } from './datasources/RemoteGraphQLDatasource';

export interface GraphQLService {
schema?: GraphQLSchema;
executor: GraphQLExecutor;
isReady: boolean;
}

export type ServiceEndpointDefinition = Pick<ServiceDefinition, 'name' | 'url'>;

export interface GatewayConfigBase {
Expand All @@ -52,7 +46,7 @@ function isLocalConfig(config: GatewayConfig): config is LocalGatewayConfig {
return 'localServiceList' in config;
}

export class ApolloGateway implements GraphQLService {
export class ApolloGateway {
public schema?: GraphQLSchema;
public isReady: boolean = false;
protected serviceMap: ServiceMap = Object.create(null);
Expand Down Expand Up @@ -95,7 +89,7 @@ export class ApolloGateway implements GraphQLService {
this.createSchema(services);
}

return { schema: this.schema, executor: this.executor };
return { schema: this.schema!, executor: this.executor };
}

protected createSchema(services: ServiceDefinition[]) {
Expand Down Expand Up @@ -264,8 +258,7 @@ export async function createGateway(
config: GatewayConfig,
): Promise<GraphQLService> {
const gateway = new ApolloGateway(config);
await gateway.load();
return gateway;
return await gateway.load();
}

export {
Expand Down
4 changes: 4 additions & 0 deletions packages/apollo-server-core/src/ApolloServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ export class ApolloServerBase {
uploads,
playground,
plugins,
gateway,
...requestOptions
} = config;

Expand Down Expand Up @@ -261,6 +262,9 @@ export class ApolloServerBase {
throw new Error(errors.map(error => error.message).join('\n\n'));
}
this.schema = schema!;
} else if (gateway) {
this.schema = gateway.schema;
this.requestOptions.executor = gateway.executor;
} else {
if (!typeDefs) {
throw Error(
Expand Down
7 changes: 7 additions & 0 deletions packages/apollo-server-core/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import { CacheControlExtensionOptions } from 'apollo-cache-control';
import { ApolloServerPlugin } from 'apollo-server-plugin-base';

import { GraphQLSchemaModule } from '@apollographql/apollo-tools';
import { GraphQLExecutor } from 'apollo-server-core/dist/requestPipelineAPI';
export { GraphQLSchemaModule };

export { KeyValueCache } from 'apollo-server-caching';
Expand Down Expand Up @@ -64,6 +65,11 @@ type BaseConfig = Pick<
| 'cache'
>;

export interface GraphQLService {
schema: GraphQLSchema;
executor: GraphQLExecutor;
}

// 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 @@ -86,6 +92,7 @@ export interface Config extends BaseConfig {
//https://github.com/jaydenseric/graphql-upload#type-uploadoptions
uploads?: boolean | FileUploadOptions;
playground?: PlaygroundConfig;
gateway?: GraphQLService;
}

export interface FileUploadOptions {
Expand Down

0 comments on commit 3c9bdc5

Please sign in to comment.