Skip to content

skip conditional selection separation when extractAllFieldsToTypesCompact is enabled#10777

Merged
eddeee888 merged 9 commits into
dotansimha:masterfrom
ikusakov2:bugfix/extractAllFieldsToTypesCompact-no-conditional-fragment
May 9, 2026
Merged

skip conditional selection separation when extractAllFieldsToTypesCompact is enabled#10777
eddeee888 merged 9 commits into
dotansimha:masterfrom
ikusakov2:bugfix/extractAllFieldsToTypesCompact-no-conditional-fragment

Conversation

@ikusakov2
Copy link
Copy Markdown
Contributor

Overview

When extractAllFieldsToTypesCompact is enabled, conditional fragment
spreads (@skip/@include) and conditional inline fragments should NOT
be separated into selectionNodesByTypeNameConditional. They should be
merged into the base selectionNodesByTypeName like regular (unconditional)
selections.

Problem

The extractAllFieldsToTypesCompact option is designed to produce
apollo-tooling-compatible type output, where all fields from an operation
(including those from conditional fragments) appear in a single flat type.
Apollo-tooling never differentiated conditional fields as optional.

However, commit introducing conditional selection separation (which makes
conditional fragment fields optional via intersection types) is incompatible
with extractAllFieldsToTypesCompact because:

  1. Processing conditional selections separately causes the same type name
    to be generated multiple times (once from the base selection, once from
    each conditional fragment), resulting in duplicate export type
    declarations — a syntax error.

  2. Conditional fragment fields from nested fragment spreads don't propagate
    transitively, causing missing fields in generated types.

  3. The _seenFieldNames deduplication in buildParentFieldName prevents
    naming conflicts but not duplicate type declarations.

Fix

When extractAllFieldsToTypesCompact is enabled, skip the conditional
check in flattenSelectionSet and treat all selections uniformly. This
restores the alpha-version behavior where conditional and unconditional
selections were processed together, producing a single merged type with
all fields.

This is semantically correct for extractAllFieldsToTypesCompact because:

  • The option targets apollo-tooling compatibility
  • Apollo-tooling never made conditional fields optional
  • Users of this option expect flat types matching the GraphQL response shape

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented May 5, 2026

🦋 Changeset detected

Latest commit: 2d47844

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

@eddeee888 eddeee888 merged commit a6a6786 into dotansimha:master May 9, 2026
19 checks passed
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.

3 participants