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

Remove unused queryId after fetchMore #4440

Merged
merged 2 commits into from
Apr 9, 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
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