Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only return newData when querying current results for no-cache or network-only queries #4352

Merged
merged 4 commits into from
Feb 16, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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. <br/>
[@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)
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
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 @@ -556,7 +556,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 @@ -982,12 +982,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