-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(graphiql-toolkit)!: accept HeadersInit #3854
base: main
Are you sure you want to change the base?
feat(graphiql-toolkit)!: accept HeadersInit #3854
Conversation
🦋 Changeset detectedLatest commit: b1ce926 The changes in this PR will be included in the next version bump. This PR includes changesets to release 2 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
I will add a changeset once I receive feedback that the changes will be accepted. |
const fetcherOptsHeaders = new Headers(fetcherOpts?.headers ?? {}); | ||
// @ts-expect-error: Current TS Config target does not support `Headers.entries()` method. | ||
// However it is reported as "widely available" and so should be fine to use. This could | ||
// would be more complicated without it. | ||
// @see https://developer.mozilla.org/en-US/docs/Web/API/Headers/entries | ||
const fetcherOptsHeadersEntries: [string, string][] = [ | ||
...fetcherOptsHeaders.entries(), | ||
]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ideally this isn't needed. However I don't want to open a pandora's box by changing the tsconfig.json
file.
Hey @acao @dimaMachina it looks like you're the current active maintainers. Could you let me know if you'll have time to look at this PR in the coming days? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is it possible to add some test to avoid regression in the future?
I assume so, I haven't looked at the existing test suit yet. I wanted to get a general thumbs up first. From what you see, this makes sense and could get merged? |
in my perspective yes once you add a test which fix current behaviour |
@dimaMachina thanks for confirming. I will proceed this or next week with adding a test and fixing anything else CI is failing on. |
@dimaMachina I've added tests and changeset. Waiting for your feedback. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tiny, human-facing
Co-authored-by: Ted Thibodeau Jr <[email protected]>
Co-authored-by: Ted Thibodeau Jr <[email protected]>
Co-authored-by: Ted Thibodeau Jr <[email protected]>
This PR enhances
graphiql-toolkit
package fetcher utility to acceptHeadersInit
type instead ofRecord<string, string>
in places where headers are accepted.This is a backwards compatible change because
Record<string, string>
is a sub-type ofHeadersInit
. As well, care in this PR has been taken to preserve the way in which same-name headers from different sources would overwrite, not merge, together.The benefit of this change is that consumers can now pass values of
Headers
or[string,string][]
type which permits the possibility of a header repeated multiple, which HTTP supports.In practice a place this issue became relevant was in my work on Hive Console's Laboratory Preflight Script feature:graphql-hive/console#6378 (comment)
-- edit: fwiw I've since realized we're not blocked by this issue.
BREAKING CHANGE:
graphiql-toolkit
functions now acceptHeadersInit
where previously a partially wider type ofRecord<string, unknown>
was accepted. Therefore you may find for example that your project is no longer type checking after this upgrade. At runtime, nothing should change since if you weren't already putting in strings they were being coerced implicitly anyways. Therefore, in practice, this should only serve to improve your code with trivial effort.