diff --git a/CHANGELOG.md b/CHANGELOG.md index 90f7a64cdfc..6a4493c8038 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,9 @@ ``` which allows the client to avoid taking defensive snapshots of past results using `cloneDeep`, as explained by [@benjamn](https://github.com/benjamn) in [#4543](https://github.com/apollographql/apollo-client/pull/4543). +- Avoid updating (and later invalidating) cache watches when `fetchPolicy` is `'no-cache'`.
+ [@bradleyayers](https://github.com/bradleyayers) in [PR #4573](https://github.com/apollographql/apollo-client/pull/4573), part of [issue #3452](https://github.com/apollographql/apollo-client/issues/3452) + ### Apollo Cache In-Memory - Support `new InMemoryCache({ freezeResults: true })` to help enforce immutability.
diff --git a/packages/apollo-client/src/core/QueryManager.ts b/packages/apollo-client/src/core/QueryManager.ts index 4fc782ad515..3c69b2eee4d 100644 --- a/packages/apollo-client/src/core/QueryManager.ts +++ b/packages/apollo-client/src/core/QueryManager.ts @@ -437,7 +437,9 @@ export class QueryManager { const requestId = this.generateRequestId(); // set up a watcher to listen to cache updates - const cancel = this.updateQueryWatch(queryId, query, updatedOptions); + const cancel = fetchPolicy !== 'no-cache' + ? this.updateQueryWatch(queryId, query, updatedOptions) + : undefined; // Initialize query in store with unique requestId this.setQuery(queryId, () => ({