diff --git a/packages/apollo-server-azure-functions/src/azureFunctionApollo.ts b/packages/apollo-server-azure-functions/src/azureFunctionApollo.ts index fd680501701..7bb171011e5 100644 --- a/packages/apollo-server-azure-functions/src/azureFunctionApollo.ts +++ b/packages/apollo-server-azure-functions/src/azureFunctionApollo.ts @@ -8,12 +8,12 @@ import { HttpQueryError, runHttpQuery, } from 'apollo-server-core'; -import { Headers } from 'apollo-server-env'; +import { Headers, ValueOrPromise } from 'apollo-server-env'; export interface AzureFunctionGraphQLOptionsFunction { - (request: FunctionRequest, context: HttpContext): - | GraphQLOptions - | Promise; + (request: FunctionRequest, context: HttpContext): ValueOrPromise< + GraphQLOptions + >; } export interface AzureFunctionHandler { diff --git a/packages/apollo-server-azure-functions/src/azureFunctions.ts b/packages/apollo-server-azure-functions/src/azureFunctions.ts index c9dbd78a553..f031ae53e6c 100644 --- a/packages/apollo-server-azure-functions/src/azureFunctions.ts +++ b/packages/apollo-server-azure-functions/src/azureFunctions.ts @@ -1,3 +1,5 @@ +import { ValueOrPromise } from 'apollo-server-env'; + export type Context = { invocationId: string; bindingData: any; @@ -147,5 +149,5 @@ export type HttpContext = Context & { }; export interface FunctionHandler { - (context: HttpContext, request: FunctionRequest): void | Promise; + (context: HttpContext, request: FunctionRequest): ValueOrPromise; } diff --git a/packages/apollo-server-cloud-functions/src/googleCloudApollo.ts b/packages/apollo-server-cloud-functions/src/googleCloudApollo.ts index 23daeb9184c..4eb89c9fe14 100644 --- a/packages/apollo-server-cloud-functions/src/googleCloudApollo.ts +++ b/packages/apollo-server-cloud-functions/src/googleCloudApollo.ts @@ -3,11 +3,11 @@ import { HttpQueryError, runHttpQuery, } from 'apollo-server-core'; -import { Headers } from 'apollo-server-env'; +import { Headers, ValueOrPromise } from 'apollo-server-env'; import { Request, Response } from 'express'; export interface CloudFunctionGraphQLOptionsFunction { - (req?: Request, res?: Response): GraphQLOptions | Promise; + (req?: Request, res?: Response): ValueOrPromise; } export function graphqlCloudFunction( diff --git a/packages/apollo-server-cloudflare/src/cloudflareApollo.ts b/packages/apollo-server-cloudflare/src/cloudflareApollo.ts index 92e385ed29a..0704fc89b9f 100644 --- a/packages/apollo-server-cloudflare/src/cloudflareApollo.ts +++ b/packages/apollo-server-cloudflare/src/cloudflareApollo.ts @@ -4,7 +4,7 @@ import { runHttpQuery, } from 'apollo-server-core'; -import { Request, Response, URL } from 'apollo-server-env'; +import { Request, Response, URL, ValueOrPromise } from 'apollo-server-env'; // Design principles: // - You can issue a GET or POST with your query. @@ -12,7 +12,7 @@ import { Request, Response, URL } from 'apollo-server-env'; // export interface CloudflareOptionsFunction { - (req?: Request): GraphQLOptions | Promise; + (req?: Request): ValueOrPromise; } export function graphqlCloudflare( diff --git a/packages/apollo-server-core/src/graphqlOptions.ts b/packages/apollo-server-core/src/graphqlOptions.ts index bcf20291c68..7112dbee057 100644 --- a/packages/apollo-server-core/src/graphqlOptions.ts +++ b/packages/apollo-server-core/src/graphqlOptions.ts @@ -12,6 +12,7 @@ import { KeyValueCache, InMemoryLRUCache } from 'apollo-server-caching'; import { DataSource } from 'apollo-datasource'; import { ApolloServerPlugin } from 'apollo-server-plugin-base'; import { GraphQLParseOptions } from 'graphql-tools'; +import { ValueOrPromise } from 'apollo-server-env'; /* * GraphQLServerOptions @@ -64,9 +65,7 @@ export default GraphQLServerOptions; export async function resolveGraphqlOptions( options: | GraphQLServerOptions - | (( - ...args: Array - ) => Promise | GraphQLServerOptions), + | ((...args: Array) => ValueOrPromise), ...args: Array ): Promise { if (typeof options === 'function') { diff --git a/packages/apollo-server-core/src/requestPipeline.ts b/packages/apollo-server-core/src/requestPipeline.ts index e2cd5970bc5..cc692f447e5 100644 --- a/packages/apollo-server-core/src/requestPipeline.ts +++ b/packages/apollo-server-core/src/requestPipeline.ts @@ -40,8 +40,8 @@ import { import { ApolloServerPlugin, GraphQLRequestListener, - WithRequired, } from 'apollo-server-plugin-base'; +import { WithRequired } from 'apollo-server-env'; import { Dispatcher } from './utils/dispatcher'; import { InMemoryLRUCache, KeyValueCache } from 'apollo-server-caching'; diff --git a/packages/apollo-server-core/src/runHttpQuery.ts b/packages/apollo-server-core/src/runHttpQuery.ts index 87da2ebd9ee..5159dc88154 100644 --- a/packages/apollo-server-core/src/runHttpQuery.ts +++ b/packages/apollo-server-core/src/runHttpQuery.ts @@ -1,4 +1,4 @@ -import { Request, Headers } from 'apollo-server-env'; +import { Request, Headers, ValueOrPromise } from 'apollo-server-env'; import { default as GraphQLOptions, resolveGraphqlOptions, @@ -16,7 +16,8 @@ import { GraphQLResponse, } from './requestPipeline'; import { CacheControlExtensionOptions } from 'apollo-cache-control'; -import { ApolloServerPlugin, WithRequired } from 'apollo-server-plugin-base'; +import { ApolloServerPlugin } from 'apollo-server-plugin-base'; +import { WithRequired } from 'apollo-server-env'; export interface HttpQueryRequest { method: string; @@ -28,7 +29,7 @@ export interface HttpQueryRequest { query: Record | Array>; options: | GraphQLOptions - | ((...args: Array) => Promise | GraphQLOptions); + | ((...args: Array) => ValueOrPromise); request: Pick; } diff --git a/packages/apollo-server-core/src/types.ts b/packages/apollo-server-core/src/types.ts index 1affbeafe8a..6f48ca91fc5 100644 --- a/packages/apollo-server-core/src/types.ts +++ b/packages/apollo-server-core/src/types.ts @@ -5,6 +5,7 @@ import { IMocks, GraphQLParseOptions, } from 'graphql-tools'; +import { ValueOrPromise } from 'apollo-server-env'; import { ConnectionContext } from 'subscriptions-transport-ws'; // The types for `ws` use `export = WebSocket`, so we'll use the // matching `import =` to bring in its sole export. @@ -32,7 +33,7 @@ export { KeyValueCache } from 'apollo-server-caching'; export type Context = T; export type ContextFunction = ( context: FunctionParams, -) => Context | Promise>; +) => ValueOrPromise>; // A plugin can return an interface that matches `ApolloServerPlugin`, or a // factory function that returns `ApolloServerPlugin`. diff --git a/packages/apollo-server-express/src/expressApollo.ts b/packages/apollo-server-express/src/expressApollo.ts index 607c699f70e..ec02f495839 100644 --- a/packages/apollo-server-express/src/expressApollo.ts +++ b/packages/apollo-server-express/src/expressApollo.ts @@ -5,11 +5,12 @@ import { runHttpQuery, convertNodeHttpToRequest, } from 'apollo-server-core'; +import { ValueOrPromise } from 'apollo-server-env'; export interface ExpressGraphQLOptionsFunction { - (req?: express.Request, res?: express.Response): - | GraphQLOptions - | Promise; + (req?: express.Request, res?: express.Response): ValueOrPromise< + GraphQLOptions + >; } // Design principles: diff --git a/packages/apollo-server-fastify/src/fastifyApollo.ts b/packages/apollo-server-fastify/src/fastifyApollo.ts index ee8945a526c..1615965b52f 100644 --- a/packages/apollo-server-fastify/src/fastifyApollo.ts +++ b/packages/apollo-server-fastify/src/fastifyApollo.ts @@ -5,12 +5,13 @@ import { } from 'apollo-server-core'; import { FastifyReply, FastifyRequest, RequestHandler } from 'fastify'; import { IncomingMessage, OutgoingMessage } from 'http'; +import { ValueOrPromise } from 'apollo-server-env'; export async function graphqlFastify( options: ( req?: FastifyRequest, res?: FastifyReply, - ) => GraphQLOptions | Promise, + ) => ValueOrPromise, ): Promise> { if (!options) { throw new Error('Apollo Server requires options.'); diff --git a/packages/apollo-server-hapi/src/hapiApollo.ts b/packages/apollo-server-hapi/src/hapiApollo.ts index c85e8f15058..7520eea810f 100644 --- a/packages/apollo-server-hapi/src/hapiApollo.ts +++ b/packages/apollo-server-hapi/src/hapiApollo.ts @@ -5,6 +5,7 @@ import { runHttpQuery, convertNodeHttpToRequest, } from 'apollo-server-core'; +import { ValueOrPromise } from 'apollo-server-env'; export interface IRegister { (server: Server, options: any, next?: Function): void; @@ -17,7 +18,7 @@ export interface IPlugin { } export interface HapiOptionsFunction { - (request?: Request): GraphQLOptions | Promise; + (request?: Request): ValueOrPromise; } export interface HapiPluginOptions { diff --git a/packages/apollo-server-integration-testsuite/src/index.ts b/packages/apollo-server-integration-testsuite/src/index.ts index 0cd9fac44a1..75a0b4e8167 100644 --- a/packages/apollo-server-integration-testsuite/src/index.ts +++ b/packages/apollo-server-integration-testsuite/src/index.ts @@ -20,6 +20,7 @@ import request = require('supertest'); import { GraphQLOptions, Config } from 'apollo-server-core'; import gql from 'graphql-tag'; +import { ValueOrPromise } from 'apollo-server-env'; export * from './ApolloServer'; @@ -189,16 +190,16 @@ export interface CreateAppOptions { excludeParser?: boolean; graphqlOptions?: | GraphQLOptions - | { (): GraphQLOptions | Promise } + | { (): ValueOrPromise } | Config; } export interface CreateAppFunc { - (options?: CreateAppOptions): any | Promise; + (options?: CreateAppOptions): ValueOrPromise; } export interface DestroyAppFunc { - (app: any): void | Promise; + (app: any): ValueOrPromise; } export default (createApp: CreateAppFunc, destroyApp?: DestroyAppFunc) => { diff --git a/packages/apollo-server-koa/src/koaApollo.ts b/packages/apollo-server-koa/src/koaApollo.ts index b25aba2d3f8..e379ba30099 100644 --- a/packages/apollo-server-koa/src/koaApollo.ts +++ b/packages/apollo-server-koa/src/koaApollo.ts @@ -5,9 +5,10 @@ import { runHttpQuery, convertNodeHttpToRequest, } from 'apollo-server-core'; +import { ValueOrPromise } from 'apollo-server-env'; export interface KoaGraphQLOptionsFunction { - (ctx: Koa.Context): GraphQLOptions | Promise; + (ctx: Koa.Context): ValueOrPromise; } export interface KoaHandler { diff --git a/packages/apollo-server-lambda/src/lambdaApollo.ts b/packages/apollo-server-lambda/src/lambdaApollo.ts index 836e7d282cf..2ce5be47853 100644 --- a/packages/apollo-server-lambda/src/lambdaApollo.ts +++ b/packages/apollo-server-lambda/src/lambdaApollo.ts @@ -4,12 +4,12 @@ import { HttpQueryError, runHttpQuery, } from 'apollo-server-core'; -import { Headers } from 'apollo-server-env'; +import { Headers, ValueOrPromise } from 'apollo-server-env'; export interface LambdaGraphQLOptionsFunction { - (event: lambda.APIGatewayProxyEvent, context: lambda.Context): - | GraphQLOptions - | Promise; + (event: lambda.APIGatewayProxyEvent, context: lambda.Context): ValueOrPromise< + GraphQLOptions + >; } export function graphqlLambda( diff --git a/packages/apollo-server-micro/src/microApollo.ts b/packages/apollo-server-micro/src/microApollo.ts index 2aad76747de..23505c1ad54 100644 --- a/packages/apollo-server-micro/src/microApollo.ts +++ b/packages/apollo-server-micro/src/microApollo.ts @@ -8,10 +8,11 @@ import url from 'url'; import { IncomingMessage, ServerResponse } from 'http'; import { MicroRequest } from './types'; +import { ValueOrPromise } from 'apollo-server-env'; // Allowed Micro Apollo Server options. export interface MicroGraphQLOptionsFunction { - (req?: IncomingMessage): GraphQLOptions | Promise; + (req?: IncomingMessage): ValueOrPromise; } // Utility function used to set multiple headers on a response object. diff --git a/packages/apollo-server-plugin-base/src/index.ts b/packages/apollo-server-plugin-base/src/index.ts index 54cb8460167..67f73bff995 100644 --- a/packages/apollo-server-plugin-base/src/index.ts +++ b/packages/apollo-server-plugin-base/src/index.ts @@ -1,5 +1,4 @@ import { ValueOrPromise, WithRequired } from 'apollo-server-env'; -export { WithRequired }; import { GraphQLServiceContext, GraphQLRequestContext,