graphql-tools
graphql-tools copied to clipboard
Default headers in `@graphql-tools/url-loader` are case sensitive
Issue workflow progress
Progress of the issue based on the Contributor Workflow
- [ ] 1. The issue provides a reproduction available on Github, Stackblitz or CodeSandbox
Make sure to fork this template and run
yarn generatein the terminal.Please make sure the GraphQL Tools package versions under
package.jsonmatches yours. - [ ] 2. A failing test has been provided
- [ ] 3. A local solution has been provided
- [ ] 4. A pull request is pending review
Describe the bug
Default headers (accept and content-type) for UrlLoader are set with the keys in lower case. If you try to override them but use capitalized keys, the headers get duplicated. For example, if I set the header the way it is demonstrated in the documentation, I send both accept and Accept headers. The same problem occurs with content-type header.
For me this produced a bag with introspection of this endpoint—https://api.spacex.land/graphql
To Reproduce Steps to reproduce the behavior:
- Create a mock
customFetchfunction to capture headers to be send - Override default headers with non-lowercase keys to the loader's
loadmethod - Provide the mock function to the loader's
loadmethod - Log the headers
How the error was found:
- Provide the loader's
loadfunction with urlhttps://api.spacex.land/graphqland set theSet-Contentheader to default value ofapplication/json - Catch the error
- Comment previously set header or make it lowercase and you won't receive the error
Expected behavior
- If the headers with internally set default values are overridden, incoming headers are made lowercase before being applied.
- There is some information provided in the documentation about those 2 headers being set by default, so people won't unnecessarily override them with the same values.
Environment:
- OS: MacOS 12.3.1
@graphql-tools/url-loader:- NodeJS: 17.3.0
Additional context