-
Notifications
You must be signed in to change notification settings - Fork 668
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ApolloStore#writeAndPublish
overwrites cache entries when using fragments
#2818
Comments
ApolloStore#writeAndPublish
overwrites cache entries when using nested fragmentsApolloStore#writeAndPublish
overwrites cache entries when using fragments
Thanks for the very detailed bug report! I made a small reproducer there: https://github.com/martinbonnin/apollo-android-samples/blob/main/reproducers/2818-fragment-overwrites/src/main/kotlin/main.kt A quick fix might be to do the merge in
That's surprising indeed. @sav007 do you have more background how come caching a network response does not follow the same path? |
For network responses we don't have to follow the same path as with writing to store via marshallers because we build normalized cache records in place where we parse network response. Means by the time we parsed network response we have already cache records, so no need to build cache records again via generated model marshallers |
OperationResponseParser now doesn't do normalization anymore. Normalization is now done from the models, like it is done when using the cache write APIs. Advantages: - Normalizing network response now uses the same path as when writing to the cache using the imperative cache write API. This ensures the results will be identical (see #2818) - Normalization can be better decoupled from the parsing and not applied at all if no cache is configured. This also means we can make normalization "async" and send a model to the UI without having to wait Inconvenients: - The whole parsing + normalization process is now slightly slower (~7%, see benchmarks) but I'm quite confident we can improve this by using the streaming parser and tweaking the normalization algorithms
Fixed in |
Summary
When calling
writeAndPublish
for anoperation
that fetches part of the schema using graphql fragments, then the information saved in cache doesn't reflect passedoperationData
.Version
2.4.6
Description
Context: We try to treat Apollo cache as a source of a truth, leveraing
ApolloStore#writeAndPublish
as a way to help Apollo cross-cache between queries or to i.e. fill incomplete data - basically we use it in edge cases, as a last resort.I noticed that despite manually writing data to cache we still experience cache misses and unexpected api calls caused by a wrong cache state. I was able to narrow down the issue down to simple repro:
Given following schema:
and a following query:
when following code invoked:
then cache gets filled with:
Expected result:
I'd expect the
name=section-name
to be saved under "section-id" cache key.More context:
where both
marshallers
write different parts of an object under the same key, overwriting previously saved partmarshaller()
mechanism isn't used with network responses and they work in an expected way.The text was updated successfully, but these errors were encountered: