Skip to content

fix(apollo-client): support Apollo Client v4 - #85

Merged
vonovak merged 2 commits into
expo:mainfrom
levizimmerman:fix/apollo-client-v4-support
Sep 21, 2026
Merged

vonovak merged 2 commits into
expo:mainfrom
levizimmerman:fix/apollo-client-v4-support

Conversation

@levizimmerman

Copy link
Copy Markdown
Contributor

Summary

Fixes #57 — the @dev-plugins/apollo-client plugin throws / stops reporting queries and mutations under Apollo Client v4.

Two internals the plugin relied on changed shape in v4:

  • getOperationName moved from @apollo/client/utilities to @apollo/client/utilities/internal (this is what the linked issue comment flagged).
  • The private client.queryManager.queries Map is gone in v4, replaced by obsQueries (not equivalent), and ObservableQuery.queryId was removed.

Rather than branching on the installed version, this switches to APIs that are public and stable across both majors:

  • Inlines the (trivial) getOperationName lookup instead of importing it, so it's no longer tied to either import path.
  • Replaces client.queryManager.queries with the public client.getObservableQueries() (a Map in v3, a Set in v4 — normalized into an array).
  • Reads document/variables/queryName directly off each ObservableQuery (public in both versions) instead of the private QueryInfo map entry, and uses getCurrentResult().data for cached data instead of the private diff/lastDiff.
  • Falls back to a generated id when ObservableQuery.queryId isn't present (v4).
  • ApolloClientType is now a small duck-typed interface instead of ApolloClient<NormalizedCacheObject>, since the ApolloClient class generic was removed entirely in v4 and the old type couldn't compile against both majors at once.
  • Declares @apollo/client as a peerDependencies range (^3.8.0 || ^4.0.0) — it was previously undeclared.

client.queryManager.mutationStore is unchanged in shape between v3 and v4, so the mutations path didn't need changes.

Test plan

  • tsc --noEmit passes with @apollo/client@3.11.10 installed
  • tsc --noEmit passes with @apollo/client@4.3.0 installed
  • Added src/__tests__/utils.test.ts covering the new getOperationName lookup and the Map/Set normalization; passes under the package's existing jest preset
  • Manual check in the example app against both @apollo/client v3 and v4 (queries + a mutation) — happy to do this if useful before merge

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>
@vonovak
vonovak merged commit a59e7cc into expo:main Sep 21, 2026
1 check failed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[@dev-plugins/apollo-client]: Missing query data. Not showing any mutations

2 participants