Repository navigation
Merge sub-selections when the same response name appears across query branches - #101
Conversation
… branches When a query selects the same field both at the base level and inside an inline fragment (or via a fragment spread), graphql-flow now merges their sub-selections into a single property — matching the GraphQL spec's CollectFields behavior and what servers actually return. Previously the second occurrence silently clobbered the first in the generated TypeScript, dropping fields from the type. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
🦋 Changeset detectedLatest commit: 1d4078c The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
|
Deferring to @jaredly & @kevinb-khan on this one! |
kevinb-khan
left a comment
There was a problem hiding this comment.
Thanks for spotting this issue and working on a fix for it. The behaviour from the test cases looks good. I'll spend some time tomorrow looking at the implementation.
| id: string; | ||
| } | null | undefined> | null | undefined; | ||
| id: string; | ||
| /** The robot's primary function*/primaryFunction: string; |
There was a problem hiding this comment.
I was wondering where primaryFunction went, but it's hiding here after the comment on the same line. 😅
| friend: { | ||
| __typename: "Animal"; | ||
| } | { |
There was a problem hiding this comment.
where did __typename: "Animal" come from? Is it just one of the variants for friend?
jaredly
left a comment
There was a problem hiding this comment.
looks right! Thanks for making this better!
| ` | ||
| query SomeQuery { | ||
| hero(episode: JEDI) { | ||
| id |
There was a problem hiding this comment.
can you select __typename here to make the output type clearer?
Summary
(For context, I ran into this issue while I was doing some new queries for assignments (which heavily use interfaces). Not a blocker for anything, just a quirk i found)
.tsoutput can change for queries that mix inline fragments with base-level selections on an interface. The field-lookup base now follows the concrete impl rather than the interface, so JSDoc descriptions are richer and split-type sub-paths use the field alias (matching howobjectPropertiesToFlowhas always worked for object types).Example
Before:
The
Human.friendstype was{ name }only —idwas silently dropped.After:
Human.friendsis{ id; name }as the server returns.Implementation
objectPropertiesToFlowflattens matching inline fragments and known fragment spreads into the current selection list, then merges Field nodes by response name before generating TS property signatures.unionOrInterfaceToFlownow routes interface-with-fragments queries throughobjectPropertiesToFlowper concrete impl (with acollectInterfaceSelectionsForPossiblehelper that picks up matching fragment contents), so the same merge fires across base + fragment branches. Unions and the fragment-free case retain the original per-selection flow — confirmed by a new regression test.Validation against
khan/frontendRan the local build against
khan/frontend@main(2,199 resolved queries). 33 files differed (~1.5%):getNotificationsForUser.tswhere queries alias a field (classroomInfo: classroom { ... }). The split-type sub-path now uses the alias, matching object-type behavior. Zero external references to the renamed names — invisible to consumers.Test plan
pnpm typecheckclean.pnpm buildclean.khan/frontend@main— no regressions in 2,199 queries.🤖 Generated with Claude Code