Skip to content

Commit

Permalink
Merge pull request #2911 from apollographql/enterprise-merge/createGa…
Browse files Browse the repository at this point in the history
…teway-interface

Add createGateway helper function
  • Loading branch information
Jackson Kearl authored Jun 27, 2019
2 parents 1435044 + 45f4e68 commit 37ca5f5
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 8 deletions.
10 changes: 2 additions & 8 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 Down Expand Up @@ -100,7 +94,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
15 changes: 15 additions & 0 deletions packages/apollo-server-core/src/ApolloServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ import {

import { Headers } from 'apollo-server-env';
import { buildServiceDefinition } from '@apollographql/apollo-tools';
import { EngineReportingOptions } from 'apollo-engine-reporting';

const NoIntrospection = (context: ValidationContext) => ({
Field(node: FieldDefinitionNode) {
Expand Down Expand Up @@ -153,6 +154,7 @@ export class ApolloServerBase {
uploads,
playground,
plugins,
gateway,
...requestOptions
} = config;

Expand Down Expand Up @@ -261,6 +263,19 @@ 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;
if (gateway.apiKey) {
if (engine === undefined) {
((engine as unknown) as EngineReportingOptions<object>) = {
apiKey: gateway.apiKey,
};
}
if (engine) {
engine.apiKey = engine.apiKey || gateway.apiKey;
}
}
} else {
if (!typeDefs) {
throw Error(
Expand Down
9 changes: 9 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,13 @@ type BaseConfig = Pick<
| 'cache'
>;

export interface GraphQLService {
load(): Promise<{
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 +94,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 37ca5f5

Please sign in to comment.