apollo-link-state icon indicating copy to clipboard operation
apollo-link-state copied to clipboard

apollo-cache-persist and apollo-link-state sync up problem

Open ajaymore opened this issue 6 years ago • 1 comments

First of all thank you all for this wonderful library, I cannot thank enough.

I am using below type definition with apollo-link-state

export const typeDefs = `
  type User {
    phoneNumber: String!,
    cognitoUsername: ID!
    name: String!
  }
  type Mutation {
    updateUser: User!
  }
`;

Now I use CachePersistor from apollo-cache-persist like below in componentDidMount

persistor.restore().then(() => this.setState({ restored: true }));

This works well. However when I change the typeDefs and add new types, and add values to the deafults they are always overwritten, since persistor.restore() is called later. If I reverse this mechanism then my cached state is overwritten by defaults. I am stuck at how to overcome this.

ajaymore avatar Apr 27 '18 11:04 ajaymore

I've encountered a similar issue recently.

Without defaults, I'd get query errors when firing resetStore. With defaults, a page refresh will somehow use those defaults instead of what has been restored by the cache persistor.

MrSaints avatar Oct 24 '18 22:10 MrSaints