Skip to content

Commit

Permalink
Only return newData when querying current results for no-cache or net…
Browse files Browse the repository at this point in the history
…work-only queries
  • Loading branch information
danilobuerger committed Jan 31, 2019
1 parent cc3706e commit 4b2bfd0
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
6 changes: 4 additions & 2 deletions packages/apollo-client/src/core/QueryManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -554,7 +554,7 @@ export class QueryManager<TStore> {
// `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 }));
}

Expand Down Expand Up @@ -971,12 +971,14 @@ export class QueryManager<TStore> {
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1580,7 +1580,7 @@ describe('ObservableQuery', () => {
fetchPolicy: 'network-only',
});
expect(stripSymbols(observable.getCurrentResult())).toEqual({
data: dataOne,
data: undefined,
loading: true,
networkStatus: 1,
partial: false,
Expand Down

0 comments on commit 4b2bfd0

Please sign in to comment.