Apollo "Store reset while query was in flight" in CI
Calling client.resetStore() or clearStore() while a query is still travelling through the link chain rejects that query with "Store reset while query was in flight". It often surfaces in tests that reset between cases.
What this error means
A test rejects with "Invariant Violation: Store reset while query was in flight (not completed in link chain)" when a teardown or auth-change resets the store before pending queries settle.
Invariant Violation: Store reset while query was in flight
(not completed in link chain)
at QueryManager.<anonymous> (.../core/QueryManager.js)Common causes
resetStore called during pending queries
A logout, auth-token change, or test teardown calls resetStore()/clearStore() while a query is still in flight, so that query is aborted.
Tests share a client across cases without awaiting
A reset between test cases runs before the previous case's in-flight requests resolve, rejecting them mid-flight.
How to fix it
Await in-flight work before resetting
- Await all pending queries/mutations before calling resetStore.
- In tests, create a fresh client per case instead of resetting a shared one.
- Handle the rejection where a reset during logout is expected behaviour.
await Promise.all(pending); // let in-flight queries settle
await client.resetStore();Isolate the client per test
Construct a new ApolloClient and InMemoryCache in each test so a reset never races a previous test's requests.
beforeEach(() => {
client = new ApolloClient({ link, cache: new InMemoryCache() });
});How to prevent it
- Await pending operations before resetStore/clearStore.
- Use a fresh client and cache per test case.
- Expect and swallow this rejection where a reset on logout is intended.