Repository navigation
fix: resolve aliases by type condition - #273
Merged
Merged
Conversation
Inline fragments and fragment spreads with different type conditions can use the same alias for different fields. The alias map was keyed by path only, so the last alias won and objects of the other type threw. Record the type conditions of each alias per path level and match them against the concrete types resolved from __typename.
For an interface result without __typename the concrete type is unknown, so type conditions that overlap with the interface now match, as aliases did before. With aliases merged across operations the last matching alias wins again, as before.
gastrobot
pushed a commit
that referenced
this pull request
Nov 14, 2026
## [2.3.1](v2.3.0...v2.3.1) (2026-11-14) ### Bug Fixes * resolve aliases by type condition ([#273](#273)) ([fcdcd29](fcdcd29))
|
🎉 This PR is included in version 2.3.1 🎉 The release is available on: Your semantic-release bot 📦🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Follow-up to #272, from its review.
Within one selection, fragments on different types can use the same alias for different fields:
The alias map was keyed by response path only, so the last alias won, and a
Bookresult threwField publishedDate not found. Selecting__typenamedidn't help, because the alias lookup never saw the concrete type.Each alias entry now records the type conditions (
... on Type,fragment X on Type) that apply at each level of its path. When walking the response, the transformer matches them against the concrete types it already resolves from__typename. Conditions on interfaces and unions match their member types. Entries without conditions match everything.Without
__typenameon an interface result, the concrete type is unknown. There, any condition that overlaps with the interface matches, soworks { ... on Book { d: date } }still resolves as onmain. When aliases from several operations are merged (no operation name), the last matching alias wins, as before.New tests in
test/transform.test.tscover unions, interfaces, named fragments, aliases nested below a type condition, and conditions on an interface. Two more cover interface results without__typenameand alias precedence across operations, so the cases that already worked keep working.🤖 Generated with Claude Code