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

defaultOptions.mutate.fetchPolicy is ignored by useMutation #5978

Closed
awinograd opened this issue Feb 22, 2020 · 5 comments · Fixed by #6715
Closed

defaultOptions.mutate.fetchPolicy is ignored by useMutation #5978

awinograd opened this issue Feb 22, 2020 · 5 comments · Fixed by #6715
Assignees
Labels
Milestone

Comments

@awinograd
Copy link

Intended outcome:

Setting defaultOptions.mutate.fetchPolicy in client instantiation should result in the option being used by useMutation when useMutation doesn't override the value.

Actual outcome:

useMutation passes { fetchPolicy: undefined } which ends up overriding the default fetchPolicy when defaultOptions are spread with override options.

Bad object merging:

options = {
...this.defaultOptions.mutate,
...options,
} as MutationOptions<T, TVariables>;

Called with undefined fetchPolicy from:

return this.refreshClient().client.mutate({
mutation,
optimisticResponse,
refetchQueries:
mutateOptions.refetchQueries || this.getOptions().refetchQueries,
awaitRefetchQueries,
update,
context: mutationContext,
fetchPolicy,
variables: mutateVariables,
...mutateOptions
});

Related issues / fixes:

#3256 (dup of this issue, but it was closed to due inactivity)
trojanowski/react-apollo-hooks#77 (related fix for same bug in react-apollo-hooks)
#3717

How to reproduce the issue:

  1. Instantiate a client with defaultOptions.mutate.fetchPolicy set to no-cache.
  2. Use useMutation without specifying any options
  3. Note that default fetchPolicy is not respected.

Versions

  System:
    OS: macOS 10.15.3
  Binaries:
    Node: 12.14.0 - ~/.nodenv/versions/12.14.0/bin/node
    Yarn: 1.17.3 - ~/programming/oui-aviva/node_modules/.bin/yarn
    npm: 6.13.4 - ~/.nodenv/versions/12.14.0/bin/npm
  Browsers:
    Chrome: 80.0.3987.116
    Firefox: 72.0.1
    Safari: 13.0.5
  npmPackages:
    @apollo/react-hooks: 3.1.3 => 3.1.3 
    apollo: ^2.21.0 => 2.21.2 
    apollo-cache-inmemory: ^1.6.3 => 1.6.3 
    apollo-cache-persist: ^0.1.1 => 0.1.1 
    apollo-client: ^2.6.8 => 2.6.8 
    apollo-link-error: ^1.1.11 => 1.1.11 
    apollo-link-http: ^1.5.15 => 1.5.15 
    apollo-link-retry: ^2.2.15 => 2.2.15 
    apollo-link-state: ^0.4.2 => 0.4.2 
    apollo-upload-client: ^11.0.0 => 11.0.0 
@Dimous
Copy link

Dimous commented Mar 11, 2020

@benjamn @hwillson please, please, fix/assign someone to fix this longstanding issue 🙏

@Titozzz
Copy link

Titozzz commented Jul 24, 2020

related to #6561 #6677 probably

@benjamn benjamn added this to the Post 3.0 milestone Jul 27, 2020
@benjamn benjamn self-assigned this Jul 27, 2020
benjamn added a commit that referenced this issue Jul 28, 2020
@benjamn
Copy link
Member

benjamn commented Jul 28, 2020

Fix incoming (sorry for the long wait!): #6715

benjamn added a commit that referenced this issue Jul 28, 2020
* Avoid clobbering default options with undefined values.

Should fix #5978, using an approach inspired by
trojanowski/react-apollo-hooks#77.

* Mention PR #6715 in CHANGELOG.md.
@awinograd
Copy link
Author

Thanks for the fix @benjamn !

@benjamn
Copy link
Member

benjamn commented Jul 28, 2020

Following up: we just published @apollo/client@3.1.0 to npm!

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 16, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants