Skip to content

fix(codegen): iteratively inline nested fragment spreads#426

Merged
wax911 merged 2 commits into
developfrom
fix/codegen-iterative-fragment-inlining
Jun 25, 2026
Merged

fix(codegen): iteratively inline nested fragment spreads#426
wax911 merged 2 commits into
developfrom
fix/codegen-iterative-fragment-inlining

Conversation

@wax911

@wax911 wax911 commented Jun 25, 2026

Copy link
Copy Markdown
Member

Description

Follow-up to #424. The original recursive fragment resolution fix assumed that AstTransformer recursively visits the children of nodes inserted via TreeTransformerUtil.changeNode. In practice it does not, so a single transformation pass leaves nested fragment spreads (e.g. ...MediaTitleFragment inside ...MediaCoreFragment) unresolved in the generated document, producing invalid GraphQL requests.

Root Cause

flattenFragments() performed a single transformer.transform(document, spreadVisitor) pass and then asserted no FragmentSpread nodes remained. Because AstTransformer does not descend into children of replacement nodes, any fragment spread nested inside an inlined fragment definition was left as an unresolved named spread.

Fix

Replace the single-pass approach with an iterative loop:

  1. Parse the document and compute the transitive closure of reachable fragments (unchanged).
  2. Detect cycles among reachable fragments (unchanged).
  3. Repeatedly transform the document with the same spreadVisitor until collectSpreadNames returns an empty set.
  4. Serialize the fully-resolved AST.

The defensive invariant check is now the loop exit condition rather than a post-hoc assertion that could throw on deeply nested fragments.

Additional changes

  • chore(ide): update IDE Gradle project settings to include all composite-build and subproject modules, and update the Kotlin compiler version from 2.0.21 to 2.4.0 to match the project toolchain.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Enhancement (Improve existing functionality)

wax911 added 2 commits June 25, 2026 14:41
AstTransformer does not recursively visit children of nodes inserted
via TreeTransformerUtil.changeNode, so a single transformation pass
leaves nested fragment spreads (e.g. ...MediaTitleFragment inside
...MediaCoreFragment) unresolved in the generated document.

Replace the single-pass approach with an iterative loop that re-parses
and re-transforms until no FragmentSpread nodes remain. The defensive
invariant check is now the loop exit condition rather than a
post-hoc assertion that could throw on deeply nested fragments.

Follow-up to #424.
Add all composite-build and subproject modules to the IDE Gradle
project settings so they are recognised by the IDE. Update the
Kotlin compiler version from 2.0.21 to 2.4.0 to match the
project toolchain.
@codacy-production

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 0 complexity · 0 duplication

Metric Results
Complexity 0
Duplication 0

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

@wax911 wax911 merged commit 64feebb into develop Jun 25, 2026
11 checks passed
@wax911 wax911 deleted the fix/codegen-iterative-fragment-inlining branch June 25, 2026 13:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant