Skip to content

Commit

Permalink
Expose context function args in executeOperation
Browse files Browse the repository at this point in the history
Fixes apollographql#2886

Integrations pass implementation-specific arguments to the context
function, but executeOperation passes no arguments. This allows the
caller of executeOperation to specify those arguments, either to emulate
the behavior of an integration or to achieve some other user-specific
behavior. This seems appropriate, as the context function is the
designated entry point for such user-specific behavior.
  • Loading branch information
bitglue committed Mar 12, 2021
1 parent ef2c007 commit 66d1bb4
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions packages/apollo-server-core/src/ApolloServer.ts
Expand Up @@ -70,6 +70,7 @@ import {
processGraphQLRequest,
GraphQLRequestContext,
GraphQLRequest,
GraphQLResponse,
APQ_CACHE_PREFIX,
} from './requestPipeline';

Expand Down Expand Up @@ -964,7 +965,11 @@ export class ApolloServerBase {

// This function is used by the integrations to generate the graphQLOptions
// from an object containing the request and other integration specific
// options
// options.
//
// integrationContextArgument vaies by integration, see
// https://www.apollographql.com/docs/apollo-server/api/apollo-server/#middleware-specific-context-fields
// or ../../docs/source/api/apollo-server.md
protected async graphQLServerOptions(
integrationContextArgument?: Record<string, any>,
): Promise<GraphQLServerOptions> {
Expand Down Expand Up @@ -1011,8 +1016,11 @@ export class ApolloServerBase {
};
}

public async executeOperation(request: GraphQLRequest) {
const options = await this.graphQLServerOptions();
public async executeOperation(
request: GraphQLRequest,
integrationContextArgument?: Record<string, any>,
): Promise<GraphQLResponse> {
const options = await this.graphQLServerOptions(integrationContextArgument);

if (typeof options.context === 'function') {
options.context = (options.context as () => never)();
Expand Down

0 comments on commit 66d1bb4

Please sign in to comment.