Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add createGateway helper function #2911

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -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 };
JacksonKearl marked this conversation as resolved.
Show resolved Hide resolved
}

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;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add a throw here if subscriptions are currently enabled? While there's an unlikely chance that some aspect of the (bolted on, but entirely separate) subscription server might startup and run right now with the current federation implementation, we're even farther from being able to support that when schema reloading comes into the picture.

While we're going to want to fix that, that's unlikely to be before Apollo Server 3 which hopes to fix subscriptions (See #2360).

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