How to pass http headers to server.executeOperation()?

Hi,
Thanks you for this amazing library!

I’m currently setting up integration testing with the official guide => Integration testing - Apollo GraphQL Docs
And it says that you should use executeOperation, it works very well until I try to pass http headers like this

server.executeOperation({
    query: MY_QUERY
    http: { headers: {'Authorization': `Bearer ${token}`} },})

Typescript error : Type ‘{ Authorization: string; }’ is not assignable to type ‘Headers’.
And it also doesn’t work when running it.

So I was wondering how does it work?

Cheers

@ulysset the executeOperation function isn’t really meant to be used with HTTP based functionality like headers; it’s meant to be used for testing when you want to skip your HTTP server altogether. Because of this, setting HTTP headers this way won’t work. Please see the End-to-end testing section of the docs for a few recommendations of tools you can use to do this. apollo-server-integration-testing is a good choice, and provides examples of settings headers in their README.

Amazing, thank you @hwillson :slight_smile:

1 Like

Solved.