Skip to content

Commit

Permalink
Clarify that the result of readQuery should not be modified (#4815)
Browse files Browse the repository at this point in the history
The `readQuery` call may return an object that is shared with the current contents of cache, which can cause some weird behavior if you mutate the `readQuery` result.

See also:
#4514
#4543
  • Loading branch information
dobesv authored and benjamn committed May 20, 2019
1 parent 4e9f370 commit b1cf815
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions docs/source/advanced/caching.md
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,8 @@ const { todo } = client.readQuery({
});
```

Note that you should not modify the return value of `readQuery` because the same object may be reused between components. If you want to update the data in the cache, create a new replacement object and pass it to `writeQuery`.

<h3 id="readfragment">readFragment</h3>

This method allows you great flexibility around the data in your cache. Whereas `readQuery` only allowed you to read data from your root query type, `readFragment` allows you to read data from _any node you have queried_. This is incredibly powerful. You use this method as follows:
Expand Down

0 comments on commit b1cf815

Please sign in to comment.