From 4b2bfd0e7cc6849ef0c664b8b1e731c6cfbed2a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Danilo=20B=C3=BCrger?= Date: Sat, 26 Jan 2019 07:47:44 +0100 Subject: [PATCH 1/3] Only return newData when querying current results for no-cache or network-only queries --- packages/apollo-client/src/core/QueryManager.ts | 6 ++++-- .../apollo-client/src/core/__tests__/ObservableQuery.ts | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/packages/apollo-client/src/core/QueryManager.ts b/packages/apollo-client/src/core/QueryManager.ts index c9c6dbaaf25..10f190713d7 100644 --- a/packages/apollo-client/src/core/QueryManager.ts +++ b/packages/apollo-client/src/core/QueryManager.ts @@ -554,7 +554,7 @@ export class QueryManager { // `no-cache` since `getCurrentQueryResult` attemps to pull from // `newData` first, following by trying the cache (which won't // find a hit for `no-cache`). - if (fetchPolicy !== 'no-cache') { + if (fetchPolicy !== 'no-cache' && fetchPolicy !== 'network-only') { this.setQuery(queryId, () => ({ newData: null })); } @@ -971,12 +971,14 @@ export class QueryManager { data: T | undefined; partial: boolean; } { - const { variables, query } = observableQuery.options; + const { variables, query, fetchPolicy } = observableQuery.options; const lastResult = observableQuery.getLastResult(); const { newData } = this.getQuery(observableQuery.queryId); // XXX test this if (newData && newData.complete) { return { data: newData.result, partial: false }; + } else if (fetchPolicy === 'no-cache' || fetchPolicy === 'network-only') { + return { data: undefined, partial: false }; } else { try { // the query is brand new, so we read from the store to see if anything is there diff --git a/packages/apollo-client/src/core/__tests__/ObservableQuery.ts b/packages/apollo-client/src/core/__tests__/ObservableQuery.ts index 3408bee3da9..f21d93fcb8b 100644 --- a/packages/apollo-client/src/core/__tests__/ObservableQuery.ts +++ b/packages/apollo-client/src/core/__tests__/ObservableQuery.ts @@ -1580,7 +1580,7 @@ describe('ObservableQuery', () => { fetchPolicy: 'network-only', }); expect(stripSymbols(observable.getCurrentResult())).toEqual({ - data: dataOne, + data: undefined, loading: true, networkStatus: 1, partial: false, From 9413782a5d23cf921f30ace521eaa02e76e1948e Mon Sep 17 00:00:00 2001 From: Hugh Willson Date: Fri, 15 Feb 2019 20:49:11 -0500 Subject: [PATCH 2/3] Changelog update --- CHANGELOG.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 172625cff2e..4aec8ed223a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,13 @@ ## Apollo Client (vNext) +## Apollo Client (vNext) + +- Fixes an issue where the `QueryManager` was accidentally returning cached + data for `network-only` queries.
+ [@danilobuerger](https://github.com/danilobuerger) in [#4352](https://github.com/apollographql/apollo-client/pull/4352) + + ## Apollo Client (2.4.13) ### Apollo Client (2.4.13) From b200a054d955daaf199aa052ee4d1d7ce8badbc7 Mon Sep 17 00:00:00 2001 From: Hugh Willson Date: Fri, 15 Feb 2019 20:52:28 -0500 Subject: [PATCH 3/3] Max bundlesize increase --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index d00c8df340d..9517e8196a5 100644 --- a/package.json +++ b/package.json @@ -34,7 +34,7 @@ { "name": "apollo-client", "path": "./packages/apollo-client/lib/bundle.min.js", - "maxSize": "9.4 kB" + "maxSize": "9.5 kB" }, { "name": "apollo-utilities",