Skip to content

Send fragment definitions instead of inlining them - #145

Merged
spawnia merged 8 commits into
masterfrom
send-fragment-definitions
Oct 6, 2026
Merged

spawnia merged 8 commits into
masterfrom
send-fragment-definitions

Conversation

@spawnia

@spawnia spawnia commented Oct 3, 2026

Copy link
Copy Markdown
Owner

Stacked on #144.

Operations sent fragments folded into inline fragments, because codegen could not resolve spreads.
Codegen now resolves them itself, so each operation sends the fragments it uses as written.

The query text of operations with fragments changes

Persisted queries or allowlists keyed by query text need regenerating.
Generated classes stay identical: the 4 changed golden files differ only in document().

Directives on fragment definitions no longer fail codegen

FoldFragments rejected them because inlining would drop them.

EndpointConfig::generateClasses() receives fragment definitions

It got the folded document before, so custom configs that read inline fragments there see spreads now.

🤖 Generated with Claude Code

FieldCollector merges the fields of each operation per response path and
concrete object type, resolving fragments itself. OperationGenerator walks
that model without traversal state, adding __typename during emission.

OperationStack and the duplicate check in ObjectLikeBuilder are gone.
FoldFragments and AddTypename now only shape the document sent to the server.

🤖 Generated with Claude Code
The field collector resolves fragments itself, so FoldFragments only served
the document sent to the server. Each operation now carries the fragments it
uses, as written by the user, which also lifts the ban on fragment directives.

Changes the document() strings of operations that use fragments.

🤖 Generated with Claude Code
🤖 Generated with Claude Code

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot review overview

🟡 Changes recommended

The advertised fragment-definition directive support lacks regression coverage.

Review effort: Balanced
Findings: 1 Low severity

Open (1)
What changed in this PR

Updates code generation to send operations with their referenced fragment definitions instead of inlining fragment selections.

Changes:

  • Removes fragment folding and collects transitively referenced fragments.
  • Applies __typename processing to fragment definitions.
  • Updates generated operation documents and changelog.
File Description
src/​Codegen/​OperationGenerator.php Collects and prints referenced fragments.
src/​Codegen/​Generator.php Preserves fragments in the wire document.
src/​Codegen/​FoldFragments.php Removes obsolete fragment inlining.
src/​Codegen/​AddTypename.php Processes fragment selection sets.
examples/​simple/​expected/​Operations/​NestedWithFragments.php Updates nested-fragment document.
examples/​simple/​expected/​Operations/​ExplicitTypename.php Preserves the fragment definition.
examples/​simple/​expected/​Operations/​ClientDirectiveFragmentSpreadQuery.php Preserves spread directives.
examples/​polymorphic/​expected/​Operations/​UserOrPost.php Preserves the polymorphic fragment.
CHANGELOG.md Records the wire-format change.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/Codegen/Generator.php
FoldFragments and AddTypename modify nodes in place, so codegen read the folded document.

🤖 Generated with Claude Code
…nt-definitions

# Conflicts:
#	src/Codegen/Generator.php
🤖 Generated with Claude Code
Base automatically changed from collect-fields to master October 6, 2026 19:24
…itions

# Conflicts:
#	src/Codegen/Generator.php
#	src/Codegen/OperationGenerator.php
@spawnia
spawnia marked this pull request as ready for review October 6, 2026 19:26
@spawnia
spawnia merged commit e436728 into master Oct 6, 2026
36 of 38 checks passed
@spawnia
spawnia deleted the send-fragment-definitions branch October 6, 2026 19:26
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.

2 participants