Skip to content

Commit

Permalink
remove unused queryId after fetchMore
Browse files Browse the repository at this point in the history
  • Loading branch information
doomsower committed Feb 13, 2019
1 parent 3530378 commit 3e77bba
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
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
4 changes: 3 additions & 1 deletion packages/apollo-client/src/core/ObservableQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -337,10 +337,11 @@ export class ObservableQuery<
}

let combinedOptions: any;
let qid: string;

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

if (fetchMoreOptions.query) {
// fetch a new query
Expand Down Expand Up @@ -374,6 +375,7 @@ export class ObservableQuery<
variables: combinedOptions.variables,
}),
);
this.queryManager.stopQuery(qid);

return fetchMoreResult as ApolloQueryResult<TData>;
});
Expand Down

0 comments on commit 3e77bba

Please sign in to comment.