feat(apollo-mock-client): support async resolvers#654
Merged
Conversation
sergey-stoyan
approved these changes
Mar 26, 2026
vladar
approved these changes
Mar 26, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
resolveMostRecentOperationto support async resolvers by awaiting the resolver return valueMockFunctionsinterface to acceptExecutionResult | Promise<ExecutionResult>as resolver return typeMotivation
Apollo Client v3.8.0 introduced PR #10229 which added a
previousResult?.networkStatus !== result.networkStatusguard tohandleErrorOrCompletedinuseQuery. This guard preventsonCompletedfrom firing on cache writes, but it interacts badly with synchronous mock resolution.The issue is that Apollo's
ObservableQuery.getCurrentResult()readsqueryInfo.networkStatus(a shared mutable property set directly bymarkReady()) andthis.last(updated later viareportResult()through zen-observable's notification chain). When mock resolution happens synchronously,markReady()setsnetworkStatus=readybefore zen-observable delivers the data throughreportResult(). This causesgetCurrentResult()to return an inconsistent intermediate state —networkStatus=readybut no data — which consumes the networkStatus transition. By the time data arrives, the guard sees no networkStatus change and blocksonCompleted.This is a known Apollo bug acknowledged by the Apollo team (#12334, #12480) that will only be fixed in Apollo Client 4.0.
By supporting async resolvers, tests can introduce a microtask boundary (
async (operation) => { ... }) that flushes pending zen-observable subscription microtasks before delivering data — matching production timing where network responses are inherently async.