Conversation
🦋 Changeset detectedLatest commit: c2a346e 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 |
…ts when a fragment is spread directly in another fragment (dotansimha#1112)
wassim-k
force-pushed
the
fix/fragment-spread
branch
from
October 1, 2026 06:00
5abcff4 to
c2a346e
Compare
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.
Description
near-operation-filenarrows the imports for a polymorphic fragment to the types a document actually uses (#1112,fixed in #1113), but only for spreads that sit under a field. A spread at the top level of another fragment
definition is never analysed, so it falls back to importing every possible type of the fragment.
CatFragment's generated file imports bothAnimalFragment_CatandAnimalFragment_Dogand uses only the first,so a project with
"noUnusedLocals": truefails to compile — the same symptom #1112 reported, through a fragmentrather than an operation. It surfaces as soon as a second type implements the interface.
analyzeFragmentTypeUsagenow also visits eachFragmentDefinition, analysing its selection set against its typecondition just as it does a field's selection set against the field's type.
Related #1112
Type of change
Screenshots/Sandbox (if appropriate/relevant):
N/A — the inline snapshot in the new test shows the generated output.
How Has This Been Tested?
#1112 - should import only interface types that are in use when spread directly in a fragment, nextto the existing [near-opeation-file] imports to interface fragment should only include types that are used in file. #1112 test and using the same schema; a new fixture spreads
AnimalFragmentat the top offragment CatFragment on Cat. The test fails without the change and passes with it.yarn build: 1592 passed, 1 skipped.Test Environment:
@graphql-codegen/near-operation-file-preset: 5.2.2 (main atda72b1235)Checklist:
CONTRIBUTING doc and the
style guidelines of this project
Further comments
The change reuses the existing
analyzeSelectionSetTypeContextrather than adding a separate path for fragmentdefinitions, so top-level spreads are narrowed by exactly the same rules as spreads under a field.
No new comments or documentation were needed: the change is a single visitor entry mirroring the existing
Fieldone, and the preset's documented behaviour is unchanged. It has no dependent changes.