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

Support cache persistence configuration #594

Open dpmillerau opened 4 months ago

dpmillerau commented 4 months ago

Your use case

We need to persist the cache using storage as per https://www.apollographql.com/docs/react/caching/advanced-topics for that our client can access results in an offline state.

The solution you'd like

In nuxt.config.ts

import { Storage } from 'unstorage'

export default defineNuxtConfig({
 ...
  apollo: {
    clients: {
      default: {
       ...
       persistCacheStorage: Storage,
      ...
      }
    }
  },

During configuration of client, something like around line 110 src/runtime/plugin.ts

import { persistCache } from 'apollo3-cache-persist';

const cache = new InMemoryCache(clientConfig.inMemoryCacheOptions)

if (clientConfig.persistCacheStorage) {
  persistCache({
    cache,
    storage: clientConfig.persistCacheStorage,
  })
}

Possible alternatives

No response

Additional information

No response