Hi All.
This feels like a bug in apollo client or in the inMemoryCache but could of course be something I’m doing wrong. Basically, using the chrome dev tools extension for apollo I can see that for the uuid of the outgoing/incoming request there are already multiple cached results. Also when I set a breakpoint in the merge function and then step back in the execution stack I can see that “existing” DOES have entries but it is voided when execution reaches policies.ts on lines 862 to 664, due to the context.overwrite boolean being truthy:
// If cache.writeQuery or cache.writeFragment was called with
// options.overwrite set to true, we still call merge functions, but
// the existing data is always undefined, so the merge function will
// not attempt to combine the incoming data with the existing data.
if (context.overwrite) {
existing = void 0;
}
After execution of the lines above, when logging out “existing” in the merge function below, it’s value is ALWAYS undefined. I don’t set the overwrite option anywhere and it’s default is supposed to be false. What am I missing, or is this a bug?
new ApolloClient({ cache: new InMemoryCache({
typePolicies: {
DataResult: {
keyFields: ["UUID", "isDelta"]
},
Query: {
fields: {
getData: {
keyArgs: ["request", ["UUID"]],
merge(existing, incoming, { readField, args, toReference }){
console.log(existing);
}
}
}
}
}
}), ApolloLink.from([
new RetryLink({
delay: {
initial: 300,
max: 30000,
jitter: false
},
attempts: {
max: retry_max,
retryIf
}
}),
new BatchHttpLink({
uri,
batchInterval: batch_interval,
headers: headers
})
])
});