apollo icon indicating copy to clipboard operation
apollo copied to clipboard

Switch to improved InMemoryCache from Apollo Client 3

Open bmulholland opened this issue 5 years ago • 4 comments

As of Apollo Client 3.0, the InMemoryCache class is provided by the @apollo/client package. No additional libraries are required.

https://www.apollographql.com/docs/react/caching/cache-configuration/

This allows us to drop the dependency on apollo-cache-inmemory.

Further, the new InMemoryCache class provides typePolicies, which allows things like converting dates from strings to JS Date objects, so this PR enables:

# apolloConfig.js, included via apollo.clientConfigs.default in nuxt.config.js
const inMemoryCacheOptions = {
  typePolicies: {
    Post: {
      fields: {
        createdAt: {
          read(createdAt) {
            return new Date(createdAt)
          },
        },
      },
    },
  },
}
export default (context) => {
  return {
    inMemoryCacheOptions
  }
}

(The above is possible already, but requires importing and initializing the new InMemoryCache manually.)

bmulholland avatar Dec 03 '20 17:12 bmulholland

I think the tests are failing on master? So it's hard to know if this change is okay, I guess.

bmulholland avatar Dec 03 '20 17:12 bmulholland

Well, FWIW, I installed it on my project and it's working fine for my limited use case.

bmulholland avatar Dec 03 '20 18:12 bmulholland

Will this impact https://github.com/nuxt-community/apollo-module/issues/376?

memic84 avatar Jan 19 '21 20:01 memic84

@memic84 I have no idea :). Try it out?

bmulholland avatar Jan 19 '21 20:01 bmulholland

This is totally out of date now.

Not sure what's happening with this project but I don't think anyone is really paying attention.

bmulholland avatar Nov 01 '23 17:11 bmulholland