Fix: Merge type selections for inline fragments with shared field names #126
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Changes
Fix codegen skipping type classes in inline fragments with shared field names
The codegen was only generating the first type class when multiple inline
fragments selected the same field name but returned different concrete types.
For example, given this query:
Where each
articlefield resolves to a different concrete type (Note, Update,InitiationCoverage), only the Note.php class would get generated. The other two
were skipped, even though the generated code still referenced them in the type
converters. This obviously broke static analysis and caused runtime errors.
The problem was in OperationStack::setSelection(). It used
??=which meant"only set if not already set":
So when processing the fragments:
so it gets ignored
Changed it to merge selections by adding only new types that haven't been
processed yet:
This selective merging ensures all types get generated while avoiding
reprocessing of types that were already handled (which would lose their
field selections).
This only affects schemas where you have inline fragments on interfaces with
fields that return different concrete types per implementation. Union types
already worked because they handle all possible types in a single pass.->
Breaking changes