-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
executeOperation does not invoke context with expected arguments #2886
Comments
Loosely related to #2727. (Just drawing connections here for planning purposes.) |
I have exactly the same problem as you. |
This solution works well for me
|
I think I'm grappling with the same issue: I'm using the express middleware for most things, but I also have an endpoint implemented in express where I want to do a GraphQL query, manipulate the result, then send the result (with express). However I'm not sure about this:
It seems like the Since different middlewares pass different arguments, can |
An additional difficulty seems to be all the ways I might work around this end up hitting some protected or private member. For example, public async executeOperation(request: GraphQLRequest) {
const options = await this.graphQLServerOptions(); But,
|
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.
The challenge here is that the arguments passed to the context function are specific to the integration and describe, well, the HTTP context. But It looks like the solution in #5026 basically is saying "if you as a user want to figure out exactly what the argument that the integration you chose passes to |
I'd say the approach isn't necessarily to be compatibility with an implementation, it just so happens for me that's convenient because:
Generally, resolvers, ApolloServerPlugins, maybe other things will sometimes need to know about things specific to the integration. The problem is the existing implementations provide that to the context function, but the one-off, anonymous integrations that are effectively created by In the case where compatibility with an existing implementation isn't possible or desired, then the context function can do some reflection on the argument provided and do the right thing. This is something we're already doing in fact, because we get requests through two different integrations. It's a little inconvenient but it seems to be part of the essential complexity of the problem, and it's manageable because all that complexity of dealing with multiple integrations converges on the context function which can then present a uniform interface to the resolvers and whatnot in whatever way makes sense for the application. |
I've released a prerelease with this fix, version |
This is released in Apollo Server 2.23.0. |
When calling
executeOperation
, context is generated for the request if context is a function. However, the context function is not invoked with any arguments, unlike when Apollo Server is used in a http environment.This prevents the context function from performing actions based on the incoming request, such as authentication, when using
executeOperation
. The incoming request (and others) are in scope at the time context is generated, as these are passed intoexecuteOperation
asGraphQLRequest
.apollo-server/packages/apollo-server-core/src/ApolloServer.ts
Line 577 in dab8506
The text was updated successfully, but these errors were encountered: