I'm trying to manage local state with apollo-link-state. I've read that you're supposed to set resolvers, defaults and cache with withClientState()
. So there we go:
const cache = new InMemoryCache();
const defaultState = {
editGraph: {
__typename: 'EditGraph',
addNodeForm: 1,
addRelForm: 'test',
editGraphForm: false
}
};
const stateLink = withClientState({
defaults: defaultState,
cache
});
const client = new ApolloClient({
link: ApolloLink.from([
stateLink,
new HttpLink(),
]),
cache
});
Then pass client to apolloProvider: <ApolloProvider client={client}>
But I'm getting the error TypeError: cache.writeData is not a function
. Which points out this line: const stateLink = withClientState({
I want to query and console.log the defaults. But I'm not getting anywhere so far.
From apollo's docs, youtube tutorials and blog articles it's clear that the cache.writeData error shouldn't appear. So why does it here?