Skip to content

Commit

Permalink
Incorporate feedback from benjamn
Browse files Browse the repository at this point in the history
  • Loading branch information
Stephen Barlow committed Mar 23, 2021
1 parent 120b108 commit 83ff39e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
8 changes: 8 additions & 0 deletions docs/source/caching/cache-configuration.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -283,25 +283,31 @@ This query returns the following result of three `Person` objects, each with a c
"allPeople": {
"people": [
{
"__typename": "Person",
"id": "cGVvcGxlOjE=",
"name": "Luke Skywalker",
"homeworld": {
"__typename": "Planet",
"id": "cGxhbmV0czox",
"name": "Tatooine"
}
},
{
"__typename": "Person",
"id": "cGVvcGxlOjI=",
"name": "C-3PO",
"homeworld": {
"__typename": "Planet",
"id": "cGxhbmV0czox",
"name": "Tatooine"
}
},
{
"__typename": "Person",
"id": "cGVvcGxlOjM=",
"name": "R2-D2",
"homeworld": {
"__typename": "Planet",
"id": "cGxhbmV0czo4",
"name": "Naboo"
}
Expand All @@ -314,6 +320,8 @@ This query returns the following result of three `Person` objects, each with a c

</ExpansionPanel>

> Notice that each object in the result includes a `__typename` field, even though our query string _didn't_ include this field. That's because Apollo Client _automatically_ queries for every object's `__typename` field.
After the result is cached, we can view the state of our cache in the Apollo Client Devtools:

<img src="../img/cache-inspector.jpg" class="screenshot" alt="The Cache tab of the Apollo Client Devtools"></img>
Expand Down
6 changes: 4 additions & 2 deletions docs/source/caching/cache-interaction.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ If your cache contains data for _all_ of the query's fields, `readQuery` returns
}
```

**Do not modify this object directly.** The same object might be returned to multiple components. To update data in the cache, instead create a replacement object and pass it to [`writeQuery`](#writequery).
> Apollo Client automatically queries for every object's `__typename`, even if you don't include this field in your query string.
**Do not modify the returned object directly.** The same object might be returned to multiple components. To update data in the cache, instead create a replacement object and pass it to [`writeQuery`](#writequery).

If the cache is missing data for _any_ of the query's fields, `readQuery` returns `null`. It does _not_ attempt to fetch data from your GraphQL server.

Expand Down Expand Up @@ -228,7 +230,7 @@ client.writeQuery({

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).
* 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`).
* _Unlike_ `writeQuery` and `writeFragment`:
* `modify` circumvents any [`merge` functions](cache-field-behavior/#the-merge-function) you've defined, which means that fields are always overwritten with exactly the values you specify.
* `modify` _cannot_ write fields that do not already exist in the cache.
Expand Down

0 comments on commit 83ff39e

Please sign in to comment.