ardatan / ardatan/graphql-tools

Default headers in `@graphql-tools/url-loader` are case sensitive

Open
#4,482 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
5.4k
Forks
830
Avg merge
10h 59m
Merged PRs (30d)
45

Description

### Issue workflow progress

_Progress of the issue based on the [Contributor Workflow](https://github.com/the-guild-org/Stack/blob/master/CONTRIBUTING.md#a-typical-contributor-workflow)_

- [ ] 1. The issue provides a reproduction available on Github, Stackblitz or CodeSandbox
> Make sure to fork this template and run `yarn generate` in the terminal.
>
> Please make sure the GraphQL Tools package versions under `package.json` matches 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](https://github.com/ardatan/graphql-tools/blob/026f0d7afad120fb599e5f10b66839091f7dacbf/website/docs/schema-loading.mdx#url-loader), 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:
1. Create a mock `customFetch` function to capture headers to be send
2. Override default headers with non-lowercase keys to the loader's `load` method
3. Provide the mock function to the loader's `load` method
4. Log the headers

[Sandbox with reproduced error](https://stackblitz.com/edit/node-5vz71l)

How the error was found:
1. Provide the loader's `load` function with url `https://api.spacex.land/graphql` and set the `Set-Content` header to default value of `application/json`
2. Catch the error
3. Comment previously set header or make it lowercase and you won't receive the error

[Sandbox with reproduction](https://stackblitz.com/edit/node-nlfnyv)

**Expected behavior**
1. If the headers with internally set default values are overridden, incoming headers are made lowercase before being applied.
2. 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**

Contributor guide

Open the contributing guide

Research direction

Start at the @graphql-tools/url-loader load entry point and trace how its default headers are combined with incoming headers, using the two linked StackBlitz reproductions to observe the result. Check website/docs/schema-loading.mdx for the documented defaults; done means overridden headers are not duplicated and the documentation explains the defaults.

Written by the indexing model from the issue text.

Assessment

Tech stack
node.js, typescript
Domain
api
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.