Skip to content

[visitor-plugin-common] fix: declare masked fragment types for unselected union members - #11047

Open
Tyagiquamar wants to merge 1 commit into
dotansimha:masterfrom
Tyagiquamar:fix-masked-union-fragment-members-10920
Open

Tyagiquamar wants to merge 1 commit into
dotansimha:masterfrom
Tyagiquamar:fix-masked-union-fragment-members-10920

Conversation

@Tyagiquamar

Copy link
Copy Markdown

Description

A fragment on a union or interface was dropping member types that selected no fields. With inlineFragmentTypes set to mask or combine, a nested spread still referred to those per-member names, so the generated TypeScript did not compile (Cannot find name).

SelectionSetToObject now keeps one type per member in that case. A member with no selected fields is Record<PropertyKey, never>. The exported fragment type is the union of those members, which is the same shape already used when every member has a selection.

Related #10920

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

A masked or combined fragment that previously collapsed to only the selected union member is now a union that includes an empty type for each unselected member. That matches the names nested spreads already generated.

How Has This Been Tested?

  • pnpm exec prettier --check on selection-set-to-object.ts, ts-documents.spec.ts, and the changeset. Result: all matched files use Prettier code style.
  • pnpm exec vitest --no-watch packages/plugins/typescript/operations/tests/ts-documents.spec.ts in node:24-bookworm with pnpm 11.24.0. Result: 114 passed, including the new #10920 case, which typechecks the generated output.
  • pnpm exec eslint packages/plugins/other/visitor-plugin-common/src/selection-set-to-object.ts on the host after an offline install. Result: exit 0.

Test Environment:

  • OS: Linux (Docker node:24-bookworm) for Prettier and Vitest; Windows for ESLint
  • @graphql-codegen/visitor-plugin-common and @graphql-codegen/typescript-operations from this branch
  • NodeJS: 24

Checklist:

  • I have followed the CONTRIBUTING doc and the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules

…cted union members

Nested spreads referenced a member type that was dropped when that member selected no fields.
@changeset-bot

changeset-bot Bot commented Oct 7, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: a12ce20

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

This PR includes changesets to release 1 package
Name Type
@graphql-codegen/visitor-plugin-common Patch

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

This branch has not been deployed

No deployments
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.

1 participant