nuxt-modules / apollo

Nuxt.js module to use Vue-Apollo. The Apollo integration for GraphQL.
https://apollo.nuxtjs.org
MIT License
929 stars 194 forks source link

fix: async queries not reading "cache" option #551

Closed MitchellRomney closed 9 months ago

MitchellRomney commented 9 months ago

I have to believe this was overlooked as there was a cache variable created and then just never used.

If there was a specific reason to not allow async queries to use the cache, please let me know.

Otherwise this is quite a major bug that has been plaguing our site for a while in which we've had to implement workarounds that aren't very fun.

netlify[bot] commented 9 months ago

Deploy Preview for apollo-module canceled.

Name Link
Latest commit f3ed75ae7443e78367ce601340c57a020f0c5aeb
Latest deploy log https://app.netlify.com/sites/apollo-module/deploys/651a997560abba000830fa65
MitchellRomney commented 9 months ago

Looking into existing open issues, I believe this should fix #472 & #536 as well.

Diizzayy commented 9 months ago

@MitchellRomney great catch! This will be apart of the next minor release.

fosterdouglas commented 9 months ago

@Diizzayy After this update, my useAsyncQuery() calls started caching? Is that to be expected? I saw the code change and it reads like it should be properly defaulting to 'no-cache' but that doesn't seem to be happening for me. I'm not using anything custom.

I tried using this in my nuxt.config.ts, but it didn't change anything:

defaultOptions: {
    query: {
      fetchPolicy: 'no-cache',
    },
},

What's the best way for me to assert that I want to use 'no-cache' while using useAsyncQuery() ? Reverting to alpha.6 has worked for me for now.

dataexcess commented 3 months ago

@Diizzayy After this update, my useAsyncQuery() calls started caching? Is that to be expected? I saw the code change and it reads like it should be properly defaulting to 'no-cache' but that doesn't seem to be happening for me. I'm not using anything custom.

I tried using this in my nuxt.config.ts, but it didn't change anything:

defaultOptions: {
    query: {
      fetchPolicy: 'no-cache',
    },
},

What's the best way for me to assert that I want to use 'no-cache' while using useAsyncQuery() ? Reverting to alpha.6 has worked for me for now.

I was stuck on this for so long! AsyncQuery does not accept an options object ? why ? Pinning to alpha.6 and adding defaultOptions worked for me. thnx!

MortenROSE commented 3 months ago

@Diizzayy After this update, my useAsyncQuery() calls started caching? Is that to be expected? I saw the code change and it reads like it should be properly defaulting to 'no-cache' but that doesn't seem to be happening for me. I'm not using anything custom. I tried using this in my nuxt.config.ts, but it didn't change anything:

defaultOptions: {
    query: {
      fetchPolicy: 'no-cache',
    },
},

What's the best way for me to assert that I want to use 'no-cache' while using useAsyncQuery() ? Reverting to alpha.6 has worked for me for now.

I was stuck on this for so long! AsyncQuery does not accept an options object ? why ? Pinning to alpha.6 and adding defaultOptions worked for me. thnx!

You can now pass an option like this:

const { data } = useAsyncQuery(gqlDocument, { cache: true })

Take a look at the recent changes: https://github.com/nuxt-modules/apollo/commit/575c1d9

@Diizzayy Now i don't have the option to disable cache for a specific query and as far as i understand right you only could disable cache in nuxt.config for all queries and have to enable it manually for every single query you write if you want to which i think is not very convenient.

Wouldn't it be better to have a enum instead of a boolean? like

const { data } = useAsyncQuery(gqlDocument, { cache: 'no-cache' })