feat: add Apollo 4.2 modern signatures to useQuery/useMutation - #6
Merged
Merged
Conversation
There was a problem hiding this comment.
Pull request overview
This PR updates glimmer-apollo’s Apollo Client integration types to align with Apollo Client 4.2 signature-style support and improve TypedDocumentNode inference for query, mutation, and subscription APIs.
Changes:
- Adds Classic/Modern signature namespaces for
useQueryanduseMutation. - Extends positional args to accept
TypedDocumentNodeand loosens mutation variables to optional partials. - Bumps Apollo Client to
^4.2.0and adds type-level tests usingexpect-type.
Reviewed changes
Copilot reviewed 9 out of 10 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
glimmer-apollo/src/-private/usables.ts |
Adds signature-style namespaces and typed Modern/Classic call signatures. |
glimmer-apollo/src/-private/query.ts |
Allows TypedDocumentNode in query positional args. |
glimmer-apollo/src/-private/mutation.ts |
Allows TypedDocumentNode, optional partial variables, and partial mutate args. |
glimmer-apollo/src/-private/subscription.ts |
Allows TypedDocumentNode in subscription positional args. |
glimmer-apollo/package.json |
Raises Apollo Client peer/dev dependency floor to 4.2. |
test-app/package.json |
Updates Apollo Client and adds expect-type for type tests. |
test-app/tests/unit/types/query-types-test.ts |
Adds type assertions for query signature inference and compatibility. |
test-app/tests/unit/types/mutation-types-test.ts |
Adds type assertions for mutation inference and optional variables. |
test-app/tests/unit/types/subscription-types-test.ts |
Adds type assertions for subscription TypedDocumentNode inference. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
ember-try release/beta/canary now resolve to ember-source 7.x, which the previous toolchain could not build: ember-cli 6.9 fails in _initVendorFiles on ember 7's package layout, and the hardcoded ember-template-compiler specifier resolves to a nonexistent path through ember 7's exports glob. Bump ember-cli, embroider packages and babel-plugin-ember-template-compilation to ember-7-aware versions, and drop compilerPath so the babel plugin auto-detects the compiler location per scenario (ember 7 layout first, ember <= 6 fallback).
Allow graphql 17 in peerDependencies
fix(test-app): support ember-source 7 in ember-try scenarios
Mirrors Apollo Client 4.2's `Signatures.Classic`/`Signatures.Modern` pattern (gated by `TypeOverrides.signatureStyle`) so consumers can drop explicit `<TData, TVariables>` generics and let TypeScript infer from a `TypedDocumentNode`. Classic remains the default and is unchanged. `useSubscription` gets the same `TypedDocumentNode` inference improvement but no Classic/Modern split, matching Apollo 4.2's own approach for subs. `MutationOptions.variables` is now `Partial<TVariables>` and optional, subsuming the pnpm patch shipped in the consuming app. Peer dep bumped to `@apollo/client@^4.2.0` (`SignatureStyle` and `NoInfer` live at `@apollo/client/utilities/internal`, only available in 4.2+).
… test - Remove stale eslint-disable directives (`qunit/no-identical-names` is not in the CI plugin set; `@typescript-eslint/no-unused-vars` directive was reported unused) from the three new type-test files. - Apply prettier formatting to the type-test files. - Extend the file-level eslint-disable in the existing mutation-test.ts to also silence `@typescript-eslint/no-unsafe-member-access`: Apollo 4.2's stricter `MutateOptions` type doesn't unwrap cleanly through sinon's `spy.args` typing, causing member access on captured call args to flag as unsafe. Behavior assertions in tests don't need stricter typing here.
Revert the Partial<TVariables> widening on MutationOptions.variables and mutate(vars?). Modern-default in d6884cc already lets call sites omit generics, so partials at the options site were no longer needed and just hid genuine schema-renamed-arg errors.
Add docs/modern-signatures.md explaining the TypeOverrides augmentation, before/after examples for each hook, the concrete type-safety wins (variables checked at the options site, .mutate(vars) checked without explicit generics), and migration gotchas for opted-in consumers (single-generic call sites, plain DocumentNode behavior). Add a one-line callout near the top of queries/mutations/subscriptions pages linking to the new page. Existing examples stay classic so they remain accurate for the default (no TypeOverrides) consumer.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
josemarluedke
force-pushed
the
feat/apollo-modern-signatures
branch
from
August 10, 2026 18:44
fcb1006 to
b910851
Compare
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.
Adds opt-in Apollo Client 4.2 "modern signatures" to
useQuery/useMutation, mirroring Apollo Client 4.2.0 (PR #13132). Classic remains the default — no source migration required for existing users (only a peer-dep bump to@apollo/client@^4.2.0; call sites compile unchanged).Why
Per Apollo's 4.2 release notes (CHANGELOG):
The switch is global, via a
TypeOverridesaugmentation:Until this PR, glimmer-apollo only exposed the classic shape, so consumers who opted in globally still got classic ergonomics out of the wrapper.
Before / After
A query with a
TypedDocumentNode<UserInfoQuery, UserInfoQueryVariables>:A mutation with required variables:
Real type-safety wins (not just less typing)
Under modern, errors that previously slipped through when call sites used wide defaults now surface at the call site:
variablesat the options site is checked against the document. A schema-renamed or wrong-typed argument becomes a compile error. Verified bytest-app/tests/unit/types/query-types-test.ts(a@ts-expect-errorrow for{ id: 123 }against anid: stringdocument)..mutate(vars)checksvarsagainst the document'sTVariables. This check exists under classic too, but only when consumers explicitly pass generics; under modern the same check holds for inferred call sites without the boilerplate.(The plan originally proposed a third item — narrowing
.datato a deep-partial shape whenerrorPolicy: 'all'— but that requires aTErrorPolicygeneric onQueryResourcethat this PR does not add. Out of scope.)Opting in
That's it. After the augmentation, drop explicit generics anywhere a
TypedDocumentNodeis available.Migration notes for modern opt-in
For consumers that opt in and use a single-generic call style with narrowly-typed documents, the modern signature is stricter about a few patterns that classic silently accepted. These are deliberate — the point of opting in is catching them — but listed here as a heads-up:
useQuery<UserInfoQuery>should drop the generic and letTypedDocumentNodeinfer. The single-generic shape no longer compiles under modern becauseTVariablesdefaults toOperationVariables, andTypedDocumentNode<UserInfoQuery, UserInfoQueryVariables>does not satisfyTypedDocumentNode<UserInfoQuery, OperationVariables>(TVariables is contravariant). Empirically verified againstproapi-webapp/UI/consoleduring the trial migration.DocumentNode(noTypedDocumentNode) still works under modern, just withunknownforTData/TVariables— no migration needed.Notes
@apollo/client/utilities/internalimport path is listed as a public subpath in Apollo'spackage.jsonexports, but theinternalnaming and lack of stability commitments suggest it's intended for advanced consumers. Apollo's own first-party hooks importNoInferandSignatureStylefrom this path (verified at@apollo/client/react/hooks/useQuery.d.ts:5).