apollo icon indicating copy to clipboard operation
apollo copied to clipboard

fetchPolicy no-cache config not working

Open sharoneh opened this issue 4 years ago • 6 comments

Version

v4.0.1-rc.1

Reproduction link

https://stackoverflow.com/questions/57415569/nuxt-js-apollo-client-how-to-disable-cache

Steps to reproduce

I'm calling the query and mutation methods inside vuex actions, through this.app.apolloProvider.defaultClient

After making a mutation, I dispatch another action querying the updated data but the nuxt page would display the old data still, and the request wasn't displayed in the network tab of devtools. I'd have to reload the whole page in the browser to get the client to fetch the new data.

I disabled the caching in nuxt.config.js as documented but the problem wasn't solved.

After several days searching for solutions, I finally found this answer in stackoverflow that saved me. After setting the fetchPolicy to 'no-cache' in a plugin, the problem was finally solved.

What is expected ?

Setting fetchPolicy to 'no-cache' in nuxt.config.js should work.

What is actually happening?

The fetchPolicy configuration in nuxt.config.js isn't working, I had to override it using a plugin.

This bug report is available on Nuxt community (#c329)

sharoneh avatar Aug 18 '20 14:08 sharoneh

@sharoneh you saved my day! Overriding default client's options works like a charm!

WhatzzUp avatar Oct 11 '20 22:10 WhatzzUp

This came in clutch! I've been on this issue for while now. Worked like a charm, thanks @sharoneh

JohnOlushola avatar Aug 25 '21 08:08 JohnOlushola

i think u can use it in your smart query too like this apollo: { postBy: { query: gql' query getPostBySlug ($slug: String = "") { postBy(slug: $slug) { id title slug date } }',error() { return false },fetchPolicy: "no-cache||network-only||cache-and-network",errorPolicy:"all|none||ignore",prefetch: true,variables() { return { slug: this.$route.params.slug } }, }, }

honeyamin avatar Sep 12 '21 00:09 honeyamin

i think u can use it in your smart query too like this apollo: { postBy: { query: gql' query getPostBySlug ($slug: String = "") { postBy(slug: $slug) { id title slug date } }',error() { return false },fetchPolicy: "no-cache||network-only||cache-and-network",errorPolicy:"all|none||ignore",prefetch: true,variables() { return { slug: this.$route.params.slug } }, }, }

i used graphql-tag and i change " ` " in my code to " ' "

honeyamin avatar Sep 12 '21 01:09 honeyamin

@sharoneh Your solution works properly for the global configuration change, but what if I want to make a specific query/mutation as no-cache, and without changing the global config using the plugin approach, this didn't work for me, any solution for that?

BennaceurHichem avatar Mar 06 '22 10:03 BennaceurHichem