Repository navigation
feat: support new option inlineReferencedFragmentsInFragmentDocuments… - #1673
Open
hoi4 wants to merge 4 commits into
Conversation
… in near-operation-file preset
🦋 Changeset detectedLatest commit: 8ffad7d 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 |
…ocuments-option-in-near-operation-file-preset
Author
|
Could you maybe have a quick look? @dotansimha ❤️ (Not sure who to tag - I hope that's fine) |
…ocuments-option-in-near-operation-file-preset
Author
|
Or maybe @eddeee888 since you were already involved in the respective change in the |
|
We hit this exact bug upgrading Validation in a real monorepo
|
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
Adds support for the
inlineReferencedFragmentsInFragmentDocumentsoption, which was added in@graphql-codegen/visitor-plugin-common7.4.0, to the near-operation-file preset.When the option is on with
documentMode: graphQLTag, each fragment document interpolates the documents of the fragments it spreads directly (${PageFragmentDoc}). Until now, the preset only imported the types of those external fragments, so the generated file failed to compile withCannot find name 'PageFragmentDoc'.With this change, a generated file also imports the
*FragmentDocof every external fragment it spreads directly (level === 0). Fragments that are only reached indirectly are not imported, because the documents that spread them already interpolate them. This also holds withdedupeFragments: true, so no unused imports are generated. When the option is off, or in any otherdocumentMode, output is unchanged.Changes:
fragment-resolver.ts: readsinlineReferencedFragmentsInFragmentDocuments(defaultfalse). IngraphQLTagmode, the*FragmentDocimport is now also emitted for directly spread external fragments.@graphql-codegen/visitor-plugin-commonto^7.4.0, which is required for the option.minorchangeset for@graphql-codegen/near-operation-file-preset.Related #1672
Type of change
How Has This Been Tested?
Added a unit test in
near-operation-file.spec.tswith a chain of three fragments (Book→Page→Line) across separate files. It checks the imports generated forBook's file:PageFragment(the type) is imported, the same as beforePageFragmentDocandPageFragmentare imported,LineFragmentDocis notdedupeFragments: true:PageFragmentDocis imported,LineFragmentDocis notdocumentMode: documentNode: imports are the same as beforeRun with
npx vitest run packages/presets/near-operation-file.Test Environment:
@graphql-codegen/near-operation-file-preset: 5.2.3 (+@graphql-codegen/visitor-plugin-common7.4.0)Checklist:
CONTRIBUTING doc and the
style guidelines of this project
Further comments
visitor-plugin-common. The preset just honors it, so it has no option of its own to document.#6520 - self-importing fragmentand#6546 - duplicate fragment importsalso fail locally on an unchangedmain, so this PR doesn't cause them. Every other test passes, including the new one.