Skip to content

Allow FragmentType to be called as FragmentType<TypedDocumentNode>#13009

Merged
phryneas merged 7 commits intorelease-4.1from
pr/FragmentType-TypedDocumentNode
Nov 13, 2025
Merged

Allow FragmentType to be called as FragmentType<TypedDocumentNode>#13009
phryneas merged 7 commits intorelease-4.1from
pr/FragmentType-TypedDocumentNode

Conversation

@phryneas
Copy link
Copy Markdown
Member

No description provided.

…but also as `FragmentType<TypedDocumentNode>`.
@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Nov 12, 2025

🦋 Changeset detected

Latest commit: a5ee13a

The changes in this PR will be included in the next version bump.

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new bot commented Nov 12, 2025

npm i https://pkg.pr.new/apollographql/apollo-client/@apollo/client@13009

commit: e34c717

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR enhances the FragmentType utility type to accept not only fragment data types (TData) but also TypedDocumentNode instances. This allows users to pass either the fragment type directly or the type of a TypedDocumentNode variable, and the type system will correctly extract the fragment data.

Key changes:

  • Modified FragmentType to use conditional type checking with DocumentTypeDecoration to handle both usage patterns
  • Added comprehensive test coverage for the new functionality
  • Updated API reports to reflect the new type signature

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/masking/types.ts Enhanced FragmentType with conditional type logic to accept both TData and TypedDocumentNode parameters
src/masking/benches/types.bench.ts Added test cases for the new FragmentType usage patterns and updated instantiation count
.changeset/few-parrots-raise.md Added changeset documenting the new feature
.api-reports/api-report.api.md Updated API report with new FragmentType signature
.api-reports/api-report-masking.api.md Updated masking API report with new FragmentType signature

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@apollo-librarian
Copy link
Copy Markdown

apollo-librarian bot commented Nov 12, 2025

✅ Docs preview ready

The preview is ready to be viewed. View the preview

File Changes

0 new, 12 changed, 0 removed
* (developer-tools)/react/(latest)/caching/cache-configuration.mdx
* (developer-tools)/react/(latest)/data/fragments.mdx
* (developer-tools)/react/(latest)/data/mutations.mdx
* (developer-tools)/react/(latest)/data/persisted-queries.mdx
* (developer-tools)/react/(latest)/data/queries.mdx
* (developer-tools)/react/(latest)/development-testing/testing.mdx
* (developer-tools)/react/(latest)/integrations/react-native.mdx
* (developer-tools)/react/(latest)/local-state/local-state-management.mdx
* (developer-tools)/react/(latest)/migrating/apollo-client-4-migration.mdx
* (developer-tools)/react/(latest)/performance/server-side-rendering.mdx
* (developer-tools)/react/(latest)/VERSIONING_POLICY.md
* (developer-tools)/react/(latest)/versioning-policy.md

Build ID: 7e5f4f94d934ad7d0d185b66
Build Logs: View logs

URL: https://www.apollographql.com/docs/deploy-preview/7e5f4f94d934ad7d0d185b66

Copy link
Copy Markdown
Member

@jerelmiller jerelmiller left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! Only had one question about why you chose one type vs another

import type { TypeOverrides } from "@apollo/client";
import type { ApplyHKTImplementationWithDefault } from "@apollo/client/utilities/internal";

import type { DocumentTypeDecoration } from "@graphql-typed-document-node/core";
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For my own education, why use DocumentTypeDecoration here instead of TypedDocumentNode?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's the "typed part" of TypedDocumentNode and what the typed-document-node helpers themselves use:

export type ResultOf<T> = T extends DocumentTypeDecoration<infer ResultType, infer VariablesType> ? ResultType : never;

It already works with TypedDocumentString too, and will likely work with all future similar additions to the family - since we don't explicitly rely on a Document here it just seems more future-proof.

@github-actions github-actions bot added the auto-cleanup 🤖 label Nov 12, 2025
@phryneas phryneas merged commit bfcd16e into release-4.1 Nov 13, 2025
31 checks passed
jerelmiller pushed a commit that referenced this pull request Nov 17, 2025
#13009)

* Allow `FragmentType` not only to be called as `FragmentType<TData>`, but also as `FragmentType<TypedDocumentNode>`.

* update non-type-import

* simplify type

* chores

* fixup 🤦

* lint

* Clean up Prettier, Size-limit, and Api-Extractor

---------

Co-authored-by: phryneas <[email protected]>
@jerelmiller jerelmiller deleted the pr/FragmentType-TypedDocumentNode branch November 17, 2025 18:16
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 18, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants