Skip to content
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

Allow missing __typename if field added by addTypenameToDocument. #5787

Merged
merged 2 commits into from Jan 13, 2020

Conversation

benjamn
Copy link
Member

@benjamn benjamn commented Jan 13, 2020

Solves #5781 by keeping data written by cache.writeData from appearing incomplete just because it does not have __typename fields that were not explicitly present in the original query.

Since InMemoryCache#transformDocument is responsible for adding these __typename fields automatically, it makes sense for the StoreReader belonging to the InMemoryCache to detect and ignore those fields later, rather than handling this somewhere else, such as the QueryManager#transform method, where transformDocument is called.

@hwillson Another way of looking at this issue is that this bit of code in the queryListenerForObserver callback is mishandling "incomplete" data, as we've observed before:

const resultFromStore: ApolloQueryResult<T> = {
  data: stale ? lastResult && lastResult.data : data,
  ...

The changes in this commit work around the problem by removing a category of __typename-related reasons why stale might be true here, but I think we still need to decide what staleness should mean for this logic.

Solves #5781 by keeping data written by cache.writeData from appearing
incomplete just because it does not have __typename fields that were not
explicitly present in the original query.

Since InMemoryCache#transformDocument is responsible for adding these
__typename fields automatically, it makes sense for the StoreReader
belonging to the InMemoryCache to detect and ignore those fields later,
rather than handling this somewhere else, like the QueryManager#transform
method, where transformDocument is called.

@hwillson Another way of looking at this issue is that this bit of code in
the queryListenerForObserver callback is mishandling "incomplete" data, as
we've observed before:

  const resultFromStore: ApolloQueryResult<T> = {
    data: stale ? lastResult && lastResult.data : data,
    ...

The changes in this commit work around the problem by removing a category
of __typename-related reasons why stale might be true here, but I think we
still need to decide what staleness should mean for this logic.
@benjamn benjamn added this to the Release 3.0 milestone Jan 13, 2020
@benjamn benjamn requested a review from hwillson January 13, 2020 15:23
@benjamn benjamn self-assigned this Jan 13, 2020
@@ -681,8 +681,15 @@ describe('Writing cache data from resolvers', () => {
console.warn = originalWarn;

cache.writeData({
id: '$ROOT_QUERY.obj',
data: { field: { field2: 2, __typename: 'Field' } },
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test began displaying a warning as a result of these changes, but I noticed it was incorrectly using the old generated ID style with $ROOT_QUERY.obj, so it was not really testing what it claimed to be testing. Fixing that problem silenced the warning.

Copy link
Member

@hwillson hwillson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome - looks great! 👍

@benjamn benjamn merged commit 1009c61 into master Jan 13, 2020
@benjamn benjamn deleted the allow-missing-__typename-if-implicitly-added branch January 13, 2020 17:01
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 16, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants