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 do not work

See original GitHub issue

I tried setting defaultOptions like this:

export const apolloClient = new ApolloClient({
  link,
  cache,
  connectToDevTools: true,
  defaultOptions: {
    watchQuery: {
      fetchPolicy: 'cache-and-network'
    },
    query: {
      fetchPolicy: 'cache-and-network'
    }
  }
})

and yet re-rendering of components does not trigger refetching, however manually setting fetchPolicy option on a particular component does achieve the intended result

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:32
  • Comments:43 (5 by maintainers)

github_iconTop GitHub Comments

19reactions
daryn-kcommented, Dec 25, 2018

Okay, guys, I think the reason is you should provide all 3 properties together (watchQuery, query and mutate):

This code works

const defaultOptions = {
  watchQuery: {
    fetchPolicy: 'cache-and-network',
    errorPolicy: 'ignore',
  },
  query: {
    fetchPolicy: 'network-only',
    errorPolicy: 'all',
  },
  mutate: {
    errorPolicy: 'all'
  }
}

This code doesn’t affect to default options:

const defaultOptions = {
  query: {
    fetchPolicy: 'network-only',
    errorPolicy: 'all',
  },
  mutate: {
    errorPolicy: 'all'
  }
}

or…

const defaultOptions = {
  query: {
    fetchPolicy: 'network-only',
    errorPolicy: 'all',
  }
}

@helios1138 @stefanholzapfel @sfilipov @hwillson please check it. It works for me.

18reactions
D-80commented, Mar 22, 2018

You have to declare defaultOptions as a constant like this:

const defaultOptions = {
  watchQuery: {
    fetchPolicy: 'cache-and-network',
    errorPolicy: 'all',
  },
  query: {
    fetchPolicy: 'cache-and-network',
    errorPolicy: 'all',
  },
  mutate: {
    errorPolicy: 'all',
  }
}

const client = new ApolloClient({
  link: from([
    logoutLink,
    errorsLink,
    httpLink
  ]),
  cache: new InMemoryCache(),
  defaultOptions
});
Read more comments on GitHub >

github_iconTop Results From Across the Web

How do I correctly type the Apollo Client defaultOptions?
Basically, the behaviour/logic of query() is not supporting this strategy. So, they block it at typing level. React useQuery() hook. And if you' ......
Read more >
class ApolloClient - Apollo GraphQL Docs
This is not the version of Apollo Client that you are using, ... To set defaultOptions when using the useQuery hook, make sure...
Read more >
QueryClient | TanStack Query Docs
The logger this client uses to log debugging information, warnings and errors. If not set, console is the default logger. defaultOptions?: DefaultOptions.
Read more >
CheckBox - defaultOptions not working - DevExpress Support
Good morning, after updating DevExtreme to 21.2.4 we are unable to use the defaultOptions of the dxCheckBox component.
Read more >
The Effect of Default Options on Retirement Savings | NBER
For each of these decisions, there is usually a default option; for example, it could be that workers are not enrolled in the...
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