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

Edits to reading and writing cached data #7864

Merged
merged 5 commits into from
Mar 23, 2021

Conversation

StephenBarlow
Copy link
Contributor

No description provided.

@StephenBarlow StephenBarlow requested a review from benjamn March 19, 2021 22:02
@StephenBarlow StephenBarlow force-pushed the sb/cache-interaction-tweaks branch from e381a70 to de12147 Compare March 22, 2021 23:18
@StephenBarlow StephenBarlow force-pushed the sb/cache-interaction-tweaks branch from de12147 to a8ec20c Compare March 22, 2021 23:28
@StephenBarlow StephenBarlow force-pushed the sb/cache-interaction-tweaks branch from 243b412 to 120b108 Compare March 22, 2021 23:46
Copy link
Member

@benjamn benjamn left a comment

Choose a reason for hiding this comment

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

LGTM, with a few suggestions about explaining __typename a bit better.

Comment on lines 280 to 287
```json
{
"data": {
"allPeople": {
"people": [
{
"id": "cGVvcGxlOjE=",
"name": "Luke Skywalker",
Copy link
Member

@benjamn benjamn Mar 23, 2021

Choose a reason for hiding this comment

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

Can we add the __typename: "Person" (and "Planet") fields to this data, and add a note about Apollo Client automatically adding those fields to the query? Otherwise it may be hard to understand how the normalization makes use of the __typename information.

const { todo } = client.readQuery({
{
todo: {
__typename: 'Todo', // __typename is automatically included
Copy link
Member

Choose a reason for hiding this comment

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

Similar to my previous comment, it might be good to explain how __typename gets automatically included?

@@ -149,12 +224,14 @@ client.writeQuery({
});
```

## `cache.modify`
## Using `cache.modify`

The `modify` method of `InMemoryCache` enables you to directly modify the values of individual cached fields, or even delete fields entirely.

* Like `writeQuery` and `writeFragment`, `modify` triggers a refresh of all active queries that depend on modified fields (unless you override this behavior).
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
* Like `writeQuery` and `writeFragment`, `modify` triggers a refresh of all active queries that depend on modified fields (unless you override this behavior).
* Like `writeQuery` and `writeFragment`, `modify` triggers a refresh of all active queries that depend on modified fields (unless you override this behavior by passing `broadcast: false`).

Not critical, but I'm assuming this is what was originally meant by "override this behavior."

@StephenBarlow StephenBarlow merged commit 2484794 into main Mar 23, 2021
@StephenBarlow StephenBarlow deleted the sb/cache-interaction-tweaks branch October 4, 2021 19:11
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 15, 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.

2 participants