Apollo-client: defualtOptions are overriden by undefined and null

Created on 22 Jul 2018  ·  2Comments  ·  Source: apollographql/apollo-client

Intended outcome:
client.watchQuery({fetchPolicy: null}) should use the fetchPolicy in defaultOptions

Actual outcome:
Instead it sets it to cache-first because it is the default behavior.

How to reproduce the issue:
https://codesandbox.io/s/8zx2m3759l
Watch your network traffic. There should be two request to the graphql endpoint but there is only one.

Versions

[email protected]

Most helpful comment

Ran into this today. It looks like React Apollo's <Query /> component works around this by compacting the options before passing them to apollo-client, but not all third party libraries using apollo-client will know about this (I ran into this with react-apollo-hooks today).

It seems that apollo-client compacting options before merging into defaultOptions would be a better solution rather than expecting other tools to know not to pass in undefined/null options?

All 2 comments

Ran into this today. It looks like React Apollo's <Query /> component works around this by compacting the options before passing them to apollo-client, but not all third party libraries using apollo-client will know about this (I ran into this with react-apollo-hooks today).

It seems that apollo-client compacting options before merging into defaultOptions would be a better solution rather than expecting other tools to know not to pass in undefined/null options?

Please try a recent version of @apollo/client and let us know if this issue is still happening. Thanks!

Was this page helpful?
0 / 5 - 0 ratings