Skip to content

Commit

Permalink
Remove unneeded queryId after fetchMore (#4440)
Browse files Browse the repository at this point in the history
  • Loading branch information
doomsower authored and benjamn committed Apr 9, 2019
1 parent 7b026d2 commit 14e0b96
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 2 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
- Avoid updating (and later invalidating) cache watches when `fetchPolicy` is `'no-cache'`. <br/>
[@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)

- Remove temporary `queryId` after `fetchMore` completes. <br/>
[@doomsower](https://github.com/doomsower) in [#4440](https://github.com/apollographql/apollo-client/pull/4440)

### Apollo Cache In-Memory

- Support `new InMemoryCache({ freezeResults: true })` to help enforce immutability. <br/>
Expand Down
35 changes: 35 additions & 0 deletions packages/apollo-client/src/__tests__/fetchMore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,41 @@ describe('fetchMore on an observable query', () => {
},
});
});

it('will not leak fetchMore query', () => {
latestResult = null;
var beforeQueryCount;
return setup({
request: {
query,
variables: variablesMore,
},
result: resultMore,
})
.then(watchedQuery => {
beforeQueryCount = Object.keys(
client.queryManager.queryStore.getStore(),
).length;
return watchedQuery.fetchMore({
variables: { start: 10 }, // rely on the fact that the original variables had limit: 10
updateQuery: (prev, options) => {
const state = cloneDeep(prev) as any;
state.entry.comments = [
...state.entry.comments,
...(options.fetchMoreResult as any).entry.comments,
];
return state;
},
});
})
.then(data => {
var afterQueryCount = Object.keys(
client.queryManager.queryStore.getStore(),
).length;
expect(afterQueryCount).toBe(beforeQueryCount);
unsetup();
});
});
});

describe('fetchMore on an observable query with connection', () => {
Expand Down
9 changes: 7 additions & 2 deletions packages/apollo-client/src/core/ObservableQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -343,11 +343,10 @@ export class ObservableQuery<
);

let combinedOptions: any;
const qid = this.queryManager.generateQueryId();

return Promise.resolve()
.then(() => {
const qid = this.queryManager.generateQueryId();

if (fetchMoreOptions.query) {
// fetch a new query
combinedOptions = fetchMoreOptions;
Expand Down Expand Up @@ -381,7 +380,13 @@ export class ObservableQuery<
}),
);

this.queryManager.stopQuery(qid);

return fetchMoreResult as ApolloQueryResult<TData>;

}, error => {
this.queryManager.stopQuery(qid);
throw error;
});
}

Expand Down

0 comments on commit 14e0b96

Please sign in to comment.