defaultOptions.mutate.fetchPolicy is ignored by useMutation
See original GitHub issueIntended 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: https://github.com/apollographql/apollo-client/blob/0340c48429b20f621d552af748527798bf6f26c5/src/ApolloClient.ts#L345-L348
Called with undefined fetchPolicy from: https://github.com/apollographql/apollo-client/blob/a38a2cad22910ef876ccbd189a1368b1dde999a4/src/react/data/MutationData.ts#L101-L112
Related issues / fixes:
https://github.com/apollographql/apollo-client/issues/3256 (dup of this issue, but it was closed to due inactivity)
https://github.com/trojanowski/react-apollo-hooks/pull/77 (related fix for same bug in react-apollo-hooks
)
https://github.com/apollographql/apollo-client/issues/3717
How to reproduce the issue:
- Instantiate a client with
defaultOptions.mutate.fetchPolicy
set tono-cache
. - Use
useMutation
without specifying any options - 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
Issue Analytics
- State:
- Created 4 years ago
- Reactions:7
- Comments:5 (2 by maintainers)
Top GitHub Comments
Thanks for the fix @benjamn !
Following up: we just published
@apollo/client@3.1.0
to npm!