apollo-cache-instorage icon indicating copy to clipboard operation
apollo-cache-instorage copied to clipboard

how to persist and restore data with an array

Open omniteq opened this issue 4 years ago • 0 comments

I'm having a really hard time trying to understand how to restore data properly. I managed to restore simple data (when key is a string) by overwriting the initial state. So before client.writeData(myInitialState) I replace values with those from the localStorage. However, it doesn't work for arrays which are somehow modified when saving to the apollo cache. For example, an initial state like this:

{
agents: []
}

is transformed (normalized?) to this:

{
agents: {type: "json", json: []}
}

When I set an initial state with the above, transformed version, my mutation doesn't work.

omniteq avatar Mar 26 '20 18:03 omniteq