diff --git a/packages/server-types/src/types.ts b/packages/server-types/src/types.ts index 1de8d0886f6..6e334af6002 100644 --- a/packages/server-types/src/types.ts +++ b/packages/server-types/src/types.ts @@ -139,12 +139,19 @@ export interface GraphQLRequest { export type VariableValues = { [name: string]: any }; +// Its not possible for this to be Record without casting either the +// result of executeOperation in ApolloServer.ts or the result of sendResponse and +// sendErrorResponse in requestPipeline.ts. +// By leaving this open as the wider object type it fulfills what a user can pass +// in which is an extension of Record. +type GraphQLResponseData = Record; + // TODO(AS4): does this differ in an interesting way from GraphQLExecutionResult // and graphql-js ExecutionResult? It does have `http` but perhaps this can be an // "extends". Ah, the difference is about formatted vs throwable errors? Let's // make sure we at least understand it. -export interface GraphQLResponse { - data?: Record | null; +export interface GraphQLResponse { + data?: TData | null; errors?: ReadonlyArray; extensions?: Record; // TODO(AS4): Seriously consider whether this type makes sense at all or whether diff --git a/packages/server/src/ApolloServer.ts b/packages/server/src/ApolloServer.ts index a57d298cbc9..e26913eeab2 100644 --- a/packages/server/src/ApolloServer.ts +++ b/packages/server/src/ApolloServer.ts @@ -1040,25 +1040,38 @@ export class ApolloServer { * The second object will be the `contextValue` object available in resolvers. */ // TODO(AS4): document this - public async executeOperation( + public async executeOperation< + TData = Record, + TVariables = Record, + >( this: ApolloServer, request: Omit & { query?: string | DocumentNode; + variables?: TVariables; }, - ): Promise; - public async executeOperation( + ): Promise>; + + public async executeOperation< + TData = Record, + TVariables = Record, + >( request: Omit & { query?: string | DocumentNode; + variables?: TVariables; }, contextValue: TContext, - ): Promise; + ): Promise>; - async executeOperation( + async executeOperation< + TData = Record, + TVariables = Record, + >( request: Omit & { query?: string | DocumentNode; + variables?: TVariables; }, contextValue?: TContext, - ): Promise { + ): Promise> { // Since this function is mostly for testing, you don't need to explicitly // start your server before calling it. (That also means you can use it with // `apollo-server` which doesn't support `start()`.)