diff --git a/packages/apollo-client/src/core/QueryManager.ts b/packages/apollo-client/src/core/QueryManager.ts index e45e93ec382..dff5cd21d49 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 })); } @@ -932,7 +932,7 @@ export class QueryManager { obs.complete(); } }); - } + }, }; // TODO: Should subscriptions also accept a `context` option to pass @@ -968,12 +968,14 @@ export class QueryManager { observableQuery: ObservableQuery, optimistic: boolean = true, ) { - 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: {}, partial: false }; } else { try { // the query is brand new, so we read from the store to see if anything is there @@ -1093,7 +1095,7 @@ export class QueryManager { return new Promise>((resolve, reject) => { // Need to assign the reject function to the rejectFetchPromise variable // in the outer scope so that we can refer to it in the .catch handler. - this.fetchQueryRejectFns.add(rejectFetchPromise = reject); + this.fetchQueryRejectFns.add((rejectFetchPromise = reject)); const subscription = execute(this.deduplicator, operation).subscribe({ next: (result: ExecutionResult) => { @@ -1188,7 +1190,6 @@ export class QueryManager { this.setQuery(queryId, ({ subscriptions }) => ({ subscriptions: subscriptions.concat([subscription]), })); - }).catch(error => { this.fetchQueryRejectFns.delete(rejectFetchPromise); throw error; diff --git a/packages/apollo-client/src/core/__tests__/ObservableQuery.ts b/packages/apollo-client/src/core/__tests__/ObservableQuery.ts index 2d9204cecba..971cad79869 100644 --- a/packages/apollo-client/src/core/__tests__/ObservableQuery.ts +++ b/packages/apollo-client/src/core/__tests__/ObservableQuery.ts @@ -1581,7 +1581,7 @@ describe('ObservableQuery', () => { fetchPolicy: 'network-only', }); expect(stripSymbols(observable.currentResult())).toEqual({ - data: dataOne, + data: {}, loading: true, networkStatus: 1, partial: false,