Skip to content

Commit

Permalink
Merge branch 'abernix/plugin-factory-function-not-class'
Browse files Browse the repository at this point in the history
  • Loading branch information
abernix committed Nov 6, 2018
2 parents 1acacf0 + 25cbd3a commit c757fe5
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 11 deletions.
8 changes: 2 additions & 6 deletions packages/apollo-server-core/src/ApolloServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -460,15 +460,11 @@ export class ApolloServerBase {
return;
}

// FIXME: We also want to support default exports and possibly module names
// but this requires adjustments to typing (see PluginDefinition type), and
// I had to give up on that for now.
this.plugins = plugins.map(plugin => {
if (typeof plugin === 'function') {
return new plugin();
} else {
return plugin as ApolloServerPlugin;
return plugin();
}
return plugin;
});
}

Expand Down
8 changes: 4 additions & 4 deletions packages/apollo-server-core/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ export type ContextFunction<T = any> = (
context: Context<T>,
) => Promise<Context<T>>;

// A plugin can return an interface that matches `ApolloServerPlugin`, or a
// factory function that returns `ApolloServerPlugin`.
export type PluginDefinition = ApolloServerPlugin | (() => ApolloServerPlugin);

export interface SubscriptionServerOptions {
path: string;
keepAlive?: number;
Expand Down Expand Up @@ -69,10 +73,6 @@ export interface Config
playground?: PlaygroundConfig;
}

export type PluginDefinition =
| ApolloServerPlugin
| (new () => ApolloServerPlugin);

export interface FileUploadOptions {
//Max allowed non-file multipart form field size in bytes; enough for your queries (default: 1 MB).
maxFieldSize?: number;
Expand Down
2 changes: 1 addition & 1 deletion packages/apollo-server-plugin-base/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export {

type ValueOrPromise<T> = T | Promise<T>;

export abstract class ApolloServerPlugin {
export interface ApolloServerPlugin {
serverWillStart?(service: GraphQLServiceContext): ValueOrPromise<void>;
requestDidStart?<TContext>(
requestContext: GraphQLRequestContext<TContext>,
Expand Down

0 comments on commit c757fe5

Please sign in to comment.