I've configured ApolloClient
like this:
import { ApolloClient, InMemoryCache } from '@apollo/client';
export const apolloClient = new ApolloClient({
uri: 'http://localhost:4000',
cache: new InMemoryCache({
dataIdFromObject: obj => obj.id as string,
addTypename: false
})
});
Now I want to use apolloClient.readFragment
to read something from the cache, however it keeps returning an empty object {}
even though it looks like it's in the cache.
console.log('readFragment',optimisticUpdate)
const {id,fragment,data} = optimisticUpdate
rollback = apolloClient.readFragment({id,fragment},true)
console.log("ROLLBACK",rollback)
apolloClient.writeFragment(optimisticUpdate)
If I remove the dataIdFromObject
and addTypename
options from InMemoryCache
and change the id
to include the typename then it seems to work, but I don't see why I should have to do that because all my IDs are guaranteed to be unique.