Skip to content

Investigate and resolve ‘Cache data may be lost when replacing domains field of a Query object’ error - #412

Merged
domw30 merged 1 commit into
developfrom
bug/type-policies-cache
Mar 14, 2022
Merged

Investigate and resolve ‘Cache data may be lost when replacing domains field of a Query object’ error#412
domw30 merged 1 commit into
developfrom
bug/type-policies-cache

Conversation

@domw30

@domw30 domw30 commented Mar 11, 2022

Copy link
Copy Markdown
Collaborator

Associated Notion Card


1. Pull request checklist

  • Notion card has been moved to the Code Review column
  • Notion card has a link to this PR
  • A reviewer has been assigned to the Notion card

2. PR type

  • bug/warning fix

3. What is the old behaviour?

Cache data may be loss - existing and incoming

Screenshot 2022-03-11 at 11 32 59

Screenshot 2022-03-10 at 21 33 34

4. What is the new behaviour?

Warning resolved by adding typePolicies to InMemoryCache

My Findings:
From my understanding, this warning occurs because there is no explicit id or _id property and in Apollo Client 3 the inMemoryCache does not create a fallback fake identifier to normalise the data.

From Apollo Docs:

If you define a merge function for a field, the cache calls that function whenever the field is about to be written with an incoming value (such as from your GraphQL server). When the write occurs, the field's new value is set to the merge function's return value, instead of the original incoming value.

Your merge function cannot push the incoming array directly onto the existing array. It must instead return a new array to prevent potential errors.

@netlify

netlify Bot commented Mar 11, 2022

Copy link
Copy Markdown

✔️ Deploy Preview for wilderworld-app ready!

🔨 Explore the source changes: f9ef7dc

🔍 Inspect the deploy log: https://app.netlify.com/sites/wilderworld-app/deploys/622b3f985293380008235365

😎 Browse the preview: https://deploy-preview-412--wilderworld-app.netlify.app/

@colbr colbr left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Makes sense! Thanks for picking this up.

@domw30
domw30 merged commit 6cc2e75 into develop Mar 14, 2022
@domw30
domw30 deleted the bug/type-policies-cache branch March 14, 2022 09:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants