You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
My API receives an authorization token in a header in the request (an ExpressRequest). When writing tests I'm creating a test-client with an Apollo Server.
The problem is that, since no Express -or any other- server is created, the executeOperation method from ApolloServer is only receiving the GraphqlRequest. The issue has been discussed here: #2277 and here: #2478.
I think it would be very useful to have the request available on the tests.
Workarounds
There are some workarounds here in other issues (like setting the context inside of tests - #2277 - , or getting the headers from the GraphqlRequest - #2478 -) but none of them solves the problem. Maybe, if the request is needed in tests, it is better to create an Apollo server with an Express -or any other- server, instead of using a testClient, but I think it would be better to have this option available in the testClient, so that is possible to do something like
Hello!
Use case
My API receives an authorization token in a header in the request (an
ExpressRequest
). When writing tests I'm creating a test-client with an Apollo Server.The problem is that, since no Express -or any other- server is created, the
executeOperation
method from ApolloServer is only receiving theGraphqlRequest
. The issue has been discussed here: #2277 and here: #2478.I think it would be very useful to have the request available on the tests.
Workarounds
There are some workarounds here in other issues (like setting the context inside of tests - #2277 - , or getting the headers from the
GraphqlRequest
- #2478 -) but none of them solves the problem. Maybe, if the request is needed in tests, it is better to create an Apollo server with an Express -or any other- server, instead of using atestClient
, but I think it would be better to have this option available in thetestClient
, so that is possible to do something likeSome possible solutions:
executeOperation
method. This should be user's responsibility.executeOperation
with the information of theGraphqlRequest
, but this mocked request should be different for each server.ApolloServerBaseTesting
with asetContext
method.I would like to know if this is intentional or if is there a possibility to improve it. In that case what do you think it would be a good solution?
apollo-server version: 2.4.8
The text was updated successfully, but these errors were encountered: