Skip to content

Commit

Permalink
fix(typing): Context template type should be 'object' and not 'any'
Browse files Browse the repository at this point in the history
```context?: ContextFunction<ExpressContext, any> | Context<any>;```
is
```context?: ContextFunction<ExpressContext, any> | any;```
which is
```context?: any;```

microsoft/TypeScript#18568

Since the ContextFunction<...> part is ignored, no type hinting will be provided when a function is passed to `context`. We don't really mean `any`, we mean an object with any shape, so we should use `object` instead
  • Loading branch information
cheapsteak committed Feb 21, 2019
1 parent 8aba81f commit d05212e
Showing 1 changed file with 4 additions and 4 deletions.
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 @@ -29,10 +29,10 @@ export { GraphQLSchemaModule };

export { KeyValueCache } from 'apollo-server-caching';

export type Context<T = any> = T;
export type ContextFunction<T = any> = (
context: Context<T>,
) => Context<T> | Promise<Context<T>>;
export type Context<T = object> = T;

// A plugin can return an interface that matches `ApolloServerPlugin`, or a
// factory function that returns `ApolloServerPlugin`.
Expand All @@ -50,7 +50,7 @@ export interface SubscriptionServerOptions {
}

type BaseConfig = Pick<
GraphQLOptions<Context<any>>,
GraphQLOptions<Context>,
| 'formatError'
| 'debug'
| 'rootValue'
Expand All @@ -71,11 +71,11 @@ export interface Config extends BaseConfig {
resolvers?: IResolvers;
schema?: GraphQLSchema;
schemaDirectives?: Record<string, typeof SchemaDirectiveVisitor>;
context?: Context<any> | ContextFunction<any>;
context?: Context | ContextFunction;
introspection?: boolean;
mocks?: boolean | IMocks;
mockEntireSchema?: boolean;
engine?: boolean | EngineReportingOptions<Context<any>>;
engine?: boolean | EngineReportingOptions<Context>;
extensions?: Array<() => GraphQLExtension>;
cacheControl?: CacheControlExtensionOptions | boolean;
plugins?: PluginDefinition[];
Expand Down

0 comments on commit d05212e

Please sign in to comment.