Skip to content
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

fix(types): use correct type for headers #9042

Closed
wants to merge 93 commits into from

Conversation

alias-mac
Copy link
Contributor

@alias-mac alias-mac commented Nov 11, 2021

When passing the headers property to createHttpLink one might think that it is ok to pass them as Headers interface, but that doesn't work because there is several places in the code that expect headers to be passed as an object.

Basically the main problem is using code like:

const apolloLink = createHttpLink({
  uri: 'some-url',
  headers: new Headers({foo: 'bar'}),
});

Keep in mind that the code above is simplified and the idea is that headers passed in are of type Headers.

TypeScript won't complain because Apollo accepts any in this type, but that isn't quite true (based on the code).
I believe that the type here should be stricter to what Apollo is actually expecting to be passed in, and perhaps revisit this later to support Headers interface.

Checklist:

  • If this PR is a new feature, please reference an issue where a consensus about the design was reached (not necessary for small changes)
  • Make sure all of the significant new logic is covered by tests

When passing the headers property to `createHttpLink` one might think
that it is ok to pass them as `Headers` interface, but that doesn't work
because there is several places in the code that expect headers to be
passed as an object.
@apollo-cla
Copy link

@alias-mac: Thank you for submitting a pull request! Before we can merge it, you'll need to sign the Apollo Contributor License Agreement here: https://contribute.apollographql.com/

@alias-mac
Copy link
Contributor Author

Sorry for the ping @benjamn, @brainkim, @jcreighton and @hwillson, but if I rebase this, can it be merged? Thanks!

@alias-mac
Copy link
Contributor Author

Any chance to get this reviewed and merged? Let me know what changes you don't agree with. Thanks!
@benjamn, @brainkim, @jcreighton and @hwillson

@jpvajda jpvajda added 🏓 awaiting-contributor-response requires input from a contributor 🏓 awaiting-team-response requires input from the apollo team and removed 🏓 awaiting-contributor-response requires input from a contributor labels May 3, 2022
Copy link
Member

@jerelmiller jerelmiller left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like a positive change to me and I see no reason not to include this. Thanks for your patience @alias-mac!

@jerelmiller
Copy link
Member

@alias-mac I just merged in main and looks like there is now some code that fails type checking that wasn't here the last time you updated this PR. Would you be willing to take a look at this and get this updated? I'd be happy to get this merged in once tests are passing.

jerelmiller and others added 16 commits November 28, 2022 09:14
* Changelog

* Add only to http-link doc

* Batch, httpLink constructor, and adv. networking
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
…raphql#10144)

keyArgs must be set to false to properly merge multiple requests when paging because "cursor" is passed in as a query variable (even though it isn't referenced in the merge function)
* updates roadmap nov 2022

* roadmap updates dec 2022

* added milestone

* Update ROADMAP.md

* Update ROADMAP.md

Co-authored-by: Jeff Auriemma <bignimbus@users.noreply.github.com>
* Introduce changesets

* Add check-prerelease workflow

* Add repository check to prevent PR creation on forks
* Better handle cached data with deferred queries

When using `useQuery` with deferred queries that already have cache data
written, the initial chunk of data would overwrite anything in the
cache, which meant cached data for deferred chunks would disappear. This
is now better handled by merging existing cache data with the initial
deferred chunk to ensure a complete result set is still returned.

* Add changeset
jerelmiller and others added 21 commits January 19, 2023 11:40
* chore(deps): update cimg/node docker tag to v19

* chore: update snapshot test when run via node v19

* chore: move preinstall script steps to test:memory

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: alessia <alessia@apollographql.com>
…apollographql#10454)

* Add `onError` and clarify `shouldResubscribe`

* Remove extra commas

Co-authored-by: Jeff Auriemma <bignimbus@users.noreply.github.com>
…raphql#10455)

* Set Stale Action debug to false

* Update operations-per-run from 100 to 500
* Allow declaration merging for DefaultContext

* Use DefaultContext instead of any

* Fix test

* Add changeset

Co-authored-by: Alessia Bellisario <alessia@apollographql.com>
Co-authored-by: Jerel Miller <jerelmiller@gmail.com>
…raphql#10321)

* chore: adds failing test for issue 10317

* chore: reset data to undefined on refetch with errorPolicy: none

* chore: use watchQuery.errorPolicy for default value

* chore: clean up test

* chore: adds changeset

* fix: shouldNotify should be false if errorPolicy: none and missing errors

* fix: do not return cache data if errorPolicy none on refetch and missing errors

* chore: undo whitespace removal

* chore: add comment and test
* chore: fix netlify ignore script

* chore: update node version, add ignore script

* fix: specify docs folder

* fix: assume base of docs

* test change detection

* revert docs change
Addresses apollographql#10457

Passes `getServerSnapshot` to `useSyncExternalStore` so that it doesn't trigger a `Missing getServerSnapshot` error when using `useFragment_experimental` on the server.

Co-authored-by: Jerel Miller <jerelmiller@gmail.com>
When passing the headers property to `createHttpLink` one might think
that it is ok to pass them as `Headers` interface, but that doesn't work
because there is several places in the code that expect headers to be
passed as an object.
@changeset-bot
Copy link

changeset-bot bot commented Jan 23, 2023

🦋 Changeset detected

Latest commit: 1f70e59

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@apollo/client Patch

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

@alessbell alessbell removed the request for review from StephenBarlow January 23, 2023 20:34
@alessbell alessbell mentioned this pull request Jan 23, 2023
3 tasks
@alessbell
Copy link
Member

Hi @alias-mac 👋 I went to add a changeset here so we can get this merged in and made a mess of the git history as you can see :) I'm going to close this one out and open a new PR that includes your commit, thanks!

@alessbell alessbell closed this Jan 23, 2023
jerelmiller pushed a commit that referenced this pull request Jan 23, 2023
* fix(types): use correct type for headers

When passing the headers property to `createHttpLink` one might think
that it is ok to pass them as `Headers` interface, but that doesn't work
because there is several places in the code that expect headers to be
passed as an object.

* chore: fix TS errors

* chore: adds changeset

Co-authored-by: Filipe Guerra <alias.mac@gmail.com>
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 23, 2023
@alias-mac alias-mac deleted the fix-headers-type branch February 28, 2023 07:55
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
🏓 awaiting-team-response requires input from the apollo team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet