question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

defaultOptions.mutate.fetchPolicy is ignored by useMutation

See original GitHub issue

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

  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 

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:7
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
awinogradcommented, Jul 28, 2020

Thanks for the fix @benjamn !

0reactions
benjamncommented, Jul 28, 2020

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

Read more comments on GitHub >

github_iconTop Results From Across the Web

Mutations in Apollo Client - Apollo GraphQL Docs
The useMutation React hook is the primary API for executing mutations in an Apollo application. To execute a mutation, you first call useMutation...
Read more >
useMutation refetchQueries not updating with no-cache
I set cookie-usage-option to 'no-cache' with defaultOptions like below. const client = new ApolloClient({ uri: "[API_URL]", cache: new ...
Read more >
React Apollo: Understanding Fetch Policy with useQuery
If you want to change a default fetch policy, use defaultOptions. const client = new ApolloClient({ uri: " ...
Read more >
@apollo/client | Yarn - Package Manager
onNextChange(setValue) to listen for future changes. ... Apollo Client 3.3.16. Bug fixes. Prevent undefined mutation result in useMutation . ... Fix useReactiveVar ...
Read more >
ApolloClient - Client (React) - Apollo GraphQL Docs
Example defaultOptions object. Copy. const defaultOptions = { watchQuery: { fetchPolicy: 'cache-and-network', errorPolicy: 'ignore', } ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found