nuxt-modules / apollo

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

fetchPolicy config not working for queries #467

Closed widmerin closed 4 months ago

widmerin commented 1 year ago

Environment


Describe the bug

I tried to change the fetch policy for apollo in the nuxt.config.ts tocache-first

    defaultOptions: {
      query: {
        fetchPolicy: 'cache-first',
      },
  ...
}

This setting has no effect on the queries, which are always executed with no-cache

Expected behaviour

Queries should use fetch Policy from defaultOptions.

Reproduction

I use nuxt@3.0.0 and @nuxtjs/apollo@5.0.0-alpha.5 Nuxt config:

 apollo: {
    defaultOptions: {
      query: {
        fetchPolicy: 'cache-first',
      },
    },
  ...
}

Query

const { data } = await useAsyncQuery(query)

Additional context

In the https://github.com/nuxt-modules/apollo/blob/v5/src/runtime/composables.ts#L51 the queries get set to no-cache, how can I overwrite this? Is there a way that I can use apollo cache for queries?

Logs

No response

keithmifsud commented 1 year ago
ssyberg commented 7 months ago

I'm oddly having the opposite problem and no-cache is not respected and always hits the cache

ssyberg commented 7 months ago

Just want to add I'm seeing this generally work for useQuery but not at all for useAsyncQuery