I won't have time to implement it. But feel free to open a PR
Is there currently a way to set defaultOptions via client configuration file?
This's works for me
{
httpEndpoint: 'http://xxxxxxxxxxxx',
apollo: {
defaultOptions: {
query: {
fetchPolicy: 'network-only'
}
}
}
}
"@nuxtjs/apollo": "^4.0.0-rc2.3"
Thanks @lin-yen - That's where I landed too. I was hoping to be able to configure the fetchPolicy for an entire client from the configuration file.
@lin-yen As I can see vue-apollo uses provider.defaultOptions instead of client.defaultOptions when building a smart query (proof).
There is no way to change provider.defaultOptions via nuxt.config.js (at least now), so I added a plugin:
// plugins/apollo-overrides.js
export default ({ app }, inject) => {
app.apolloProvider.defaultOptions = {
$query: {
fetchPolicy: 'no-cache'
}
}
}
Is there a better way to change provider.defaultOptions?
ps. I'm totally new to nuxt/vue and vue-apollo
@ndan thats the preferred way for now 馃憤
@dohomi Would you accept a PR for this? Would be very useful to set defaultOptions on nuxtjs.config.js
https://www.apollographql.com/docs/react/api/apollo-client.html#apollo-client
watchQuery: {
fetchPolicy: 'cache-and-network',
errorPolicy: 'ignore',
},
query: {
fetchPolicy: 'network-only',
errorPolicy: 'all',
},
mutate: {
errorPolicy: 'all'
}
@robsontenorio yes go ahead. Currently I'm very busy in job so I might some longer time to review. I also still wait for the Vue 2.6 release which will fix SSR issues of this package and then I hope the integration is smooth for all users
First off, thanks to @robsontenorio for getting this in, I just wasted a good chunk of my day trying to disable apollo's cache and this thread helped quite a bit. However, it seems that while this PR fixed the core issue, the example provided in the readme didn't translate well into the the multi-client setup i have in my app. I tried adding the the defaultOptions to the main apollo config in nuxt.config.js, but found that they didn't show up when i inspected the particular client i was using. The solution was to add the default options to the client config like so...
nuxt.config.js
apollo: {
clientConfigs: {
default: '~/client-config.ts'
},
},
client-config.ts
import { InMemoryCache } from "apollo-cache-inmemory";
export default function(){
return {
cache: new InMemoryCache(),
apollo: {
defaultOptions: {
watchQuery: {
fetchPolicy: 'no-cache',
},
query: {
fetchPolicy: 'no-cache',
},
mutate: {
fetchPolicy: 'no-cache',
},
},
}
}
}
Hopefully this helps the next person.
Most helpful comment
First off, thanks to @robsontenorio for getting this in, I just wasted a good chunk of my day trying to disable apollo's cache and this thread helped quite a bit. However, it seems that while this PR fixed the core issue, the example provided in the readme didn't translate well into the the multi-client setup i have in my app. I tried adding the the defaultOptions to the main apollo config in nuxt.config.js, but found that they didn't show up when i inspected the particular client i was using. The solution was to add the default options to the client config like so...
nuxt.config.js
client-config.ts
Hopefully this helps the next person.