From b1cf815e3590696b29bb383a747355b481b1cc94 Mon Sep 17 00:00:00 2001 From: Dobes Vandermeer Date: Mon, 20 May 2019 13:53:55 -0700 Subject: [PATCH] Clarify that the result of `readQuery` should not be modified (#4815) 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: https://github.com/apollographql/apollo-client/pull/4514 https://github.com/apollographql/apollo-client/pull/4543 --- docs/source/advanced/caching.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/source/advanced/caching.md b/docs/source/advanced/caching.md index 09ea8a9aca5..e00f9299c8b 100644 --- a/docs/source/advanced/caching.md +++ b/docs/source/advanced/caching.md @@ -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`. +

readFragment

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: