Skip to content

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

@vuode

Description

@vuode

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 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, 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

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

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions