Repository navigation
fix(apollo-client): support Apollo Client v4 - #85
Merged
Merged
Conversation
Apollo Client v4 moved getOperationName to a different import path and removed the private queryManager.queries map and ObservableQuery.queryId that the plugin relied on. Replace both with public, version-stable APIs (getObservableQueries(), ObservableQuery.getCurrentResult()) and inline the tiny getOperationName lookup instead of importing it, so the same code works against @apollo/client v3 and v4 without branching. Fixes expo#57
…ameter type `cache.extract()` returns `unknown` in v4, so a real `ApolloClient` did not satisfy the duck-typed `ApolloClientType`. Also shorten comments. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
5 tasks done
vonovak
approved these changes
Sep 21, 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
Fixes #57 — the
@dev-plugins/apollo-clientplugin throws / stops reporting queries and mutations under Apollo Client v4.Two internals the plugin relied on changed shape in v4:
getOperationNamemoved from@apollo/client/utilitiesto@apollo/client/utilities/internal(this is what the linked issue comment flagged).client.queryManager.queriesMapis gone in v4, replaced byobsQueries(not equivalent), andObservableQuery.queryIdwas removed.Rather than branching on the installed version, this switches to APIs that are public and stable across both majors:
getOperationNamelookup instead of importing it, so it's no longer tied to either import path.client.queryManager.querieswith the publicclient.getObservableQueries()(aMapin v3, aSetin v4 — normalized into an array).document/variables/queryNamedirectly off eachObservableQuery(public in both versions) instead of the privateQueryInfomap entry, and usesgetCurrentResult().datafor cached data instead of the privatediff/lastDiff.ObservableQuery.queryIdisn't present (v4).ApolloClientTypeis now a small duck-typed interface instead ofApolloClient<NormalizedCacheObject>, since theApolloClientclass generic was removed entirely in v4 and the old type couldn't compile against both majors at once.@apollo/clientas apeerDependenciesrange (^3.8.0 || ^4.0.0) — it was previously undeclared.client.queryManager.mutationStoreis unchanged in shape between v3 and v4, so the mutations path didn't need changes.Test plan
tsc --noEmitpasses with@apollo/client@3.11.10installedtsc --noEmitpasses with@apollo/client@4.3.0installedsrc/__tests__/utils.test.tscovering the newgetOperationNamelookup and theMap/Setnormalization; passes under the package's existing jest preset@apollo/clientv3 and v4 (queries + a mutation) — happy to do this if useful before merge