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
apollo-server-core: pass req obj to context when invoking executeOperation #2478
apollo-server-core: pass req obj to context when invoking executeOperation #2478
Conversation
…ation Fixes apollographql#2277. `apollo-server-testing` relies on `apollo-server-core` to execute queries for integration tests, via the `executeOperation` method. However, when executing a query via `executeOperation`, `apollo-server-core` was not passing the `req` object to the `context` callback function used to create the server. This is fine if you're using a mock `context` object directly in your tests, but for tests that want to run a `context` callback that contains logic that depends on that `req` object, it would fail. Note that long-term the best fix for this is that `apollo-server-testing` should use the `ApolloServer` class from `apollo-server-express` internally, instead of `ApolloServerBase` from `apollo-server-core`, since it seems like that is the class that is used by default in `apollo-server`.
c28fb31
to
93909b4
Compare
Nevermind, I just noticed that the I wonder if it makes sense to create a separate testing package specifically for |
…ation Fixes apollographql#2277. `apollo-server-testing` relies on `apollo-server-core` to execute queries for integration tests. However, `apollo-server-core` was not passing the `req` object to the `context` callback function used to create the server. This is fine if you're using a mock `context` object directly in your tests, but for tests that want to run a `context` callback that contains logic that depends on that `req` object, it would fail. Note that long-term the best fix for this is that `apollo-server-testing` should use the `ApolloServer` class from `apollo-server-express` internally, since it seems like that is the class that is used by default in `apollo-server`.
Hello @vitorbal ! |
@lnmedrano if you look at the implementation of So there are basically two ways to create an apollo-server: With a), your integration tests will need to pass to the with b), since the server created for you uses express behind the scenes, So to summarize, the type of the Now let's talk about The Hopefully my explanation makes sense! Let me know if I missed anything. |
Also, @lnmedrano (or anyone else reading this), since closing this PR, I've written a new package that mimics the https://github.com/zapier/apollo-server-integration-testing We've been using it successfully at my company for the last 6 months to write real integration tests. Posting it here in case anyone else is interested in giving it a try :) |
Fixes #2277.
apollo-server-testing
relies onapollo-server-core
to execute queries for integration tests, via theexecuteOperation
method.However, when executing a query via
executeOperation
,apollo-server-core
was not passing thereq
object to thecontext
callback function used to create the server.This is fine if you're using a mock
context
object directly in your tests, but for tests that want to run acontext
callback that contains logic that depends on thatreq
object, it would fail.Note that long-term the best fix for this is probably that
apollo-server-testing
should use theApolloServer
class fromapollo-server-express
internally, instead ofApolloServerBase
fromapollo-server-core
, since it seems like that is the class that is used by default inapollo-server
.TODO: