Intended outcome:
Set up default options to use for apollo-boost.
Actual outcome:
Warning appears indicating no support for defaultOptions.
How to reproduce the issue:
https://codesandbox.io/s/4r3x3lm9z7
Set up a basic apollo app using apollo-boost and add the default options which are documented here - https://www.apollographql.com/docs/react/api/apollo-client.html#apollo-client
Versions
System:
OS: macOS High Sierra 10.13.6
Binaries:
Node: 10.8.0 - /usr/local/bin/node
Yarn: 1.9.2 - ~/.npm-global/bin/yarn
npm: 5.8.0 - ~/.npm-global/bin/npm
Browsers:
Chrome: 68.0.3440.106
Firefox: 61.0
Safari: 11.1.2
npmPackages:
apollo-boost: ^0.1.15 => 0.1.15
apollo-client: ^2.3.5 => 2.4.1
apollo-link-schema: ^1.1.0 => 1.1.0
apollo-server-express: ^2.0.0 => 2.0.4
react-apollo: ^2.1.9 => 2.1.11
In the meantime you can go with something like this:
import ApolloClient from "apollo-boost";
const client = new ApolloClient({
uri: "/query",
});
client.defaultOptions = {
watchQuery: {
fetchPolicy: 'cache-and-network',
errorPolicy: 'all',
},
query: {
fetchPolicy: 'cache-and-network'
}
};
Thanks, the warning is gone with this approach. If I get some time I'd like to open a PR to fix this problem but I'm not sure when that would be.
Is this feature needed? I wouldn't mind implementing it.
I wanted to change the default caching behavior as it didn't fit my needs. Thus, I needed this feature. Since my needs further evolved, I eventually switched to using the Apollo client directly.
Can this be merged? We ran into this issue and would also like to be able to provide defaultOptions on the ApolloClient
instance.
The comments above suggest you can define errorPolicy and fetchPolicy on client options for Apollo Boost, but Configuration Options doesnt suggest this is so
As far as I remember, Apollo Boost returns the fully fledged Apollo Client. Thus the attribute client.defaultOptions = {鈥
will be set on the actual Apollo Client.
What is being meant is that there is no way of doing a small customization to it without doing a full transition to the apollo-client
itself.
I tried the example presented by robsdedude client.defaultOptions
which didnt seem to allow me to change errorPolicy
or fetchPolicy
. The docs suggest you cant change these anyway with apollo-boost
.
I am confused from my own lack of understanding. This change will introduce the ability to make those small changes to errorPolicy
for example, without migrating to apollo-client
? If that is the case doesnt robsdedude suggestion suggest it can be done now in a slightly different way?
I just ran into this issue. The work around fixed for me but I wish it were more clearly documented
Same here, this must be supported by apollo-boost
Why #3934 has been closed?
Once apollo-client v3 is released, I think the apollo-boost package will go away.
It isn't available in constructor, but is available as prop:
client.defaultOptions = {}
Most helpful comment
In the meantime you can go with something like this: