Skip to content

[near-operation-file-preset] Fix missing fragment document imports for nested fragments (graphQLTag)#1530

Open
wassim-k wants to merge 1 commit into
dotansimha:mainfrom
wassim-k:fix/near-operation-file-fragment-import
Open

[near-operation-file-preset] Fix missing fragment document imports for nested fragments (graphQLTag)#1530
wassim-k wants to merge 1 commit into
dotansimha:mainfrom
wassim-k:fix/near-operation-file-fragment-import

Conversation

@wassim-k

@wassim-k wassim-k commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

Description

Since visitor-plugin-common v7, in documentMode: graphQLTag (default) an operation document inlines every fragment it transitively spreads, while a fragment document inlines nothing. The preset still imports *Docs by direct-spread (level === 0), so:

  • operation files miss the *Doc of fragments reached through another fragment → Cannot find name 'XFragmentDoc';
  • fragment files import *Docs they no longer interpolate → unused imports.

Reproduction

query List { list { ...Book } }, fragment Book on Book { pages { ...Page } }, fragment Page on Page { id } — each in its own file.

// queries.generated.ts
import { BookFragmentDoc } from './book-fragment.generated';
// ❌ missing: PageFragmentDoc
export const ListDocument = gql`query List{list{...Book}} ${BookFragmentDoc} ${PageFragmentDoc}`; // PageFragmentDoc undefined

Type of change

  • Bug fix (non-breaking change which fixes an issue)

How Has This Been Tested?

Added new unit tests and ran the fixed version against our codebase with 100s of GraphQL queries

Notes

I have taken some liberty in trimming some code paths that are no longer used, which coincidentally happens to be my code from across the years

@changeset-bot

changeset-bot Bot commented Jun 29, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 5a8e411

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@graphql-codegen/near-operation-file-preset Patch

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

@wassim-k
wassim-k force-pushed the fix/near-operation-file-fragment-import branch from c075f95 to e8bcf2f Compare June 29, 2026 00:39
…r nested fragments (graphQLTag)

Since visitor-plugin-common v7, graphQLTag operations inline every transitively-spread fragment, so import a fragment's *Doc wherever it's interpolated, not just at direct-spread level.
@wassim-k

Copy link
Copy Markdown
Contributor Author

Hi @eddeee888, the tests for this fix will only pass once the client plugins (typescript-stencil-apollo, typescript-react-apollo) are on visitor-plugin-common v7, and v7 then needs the empty-import guard. The repo's plugins are currently split across v6/v7, and the preset can't be correct for both.

What are your thoughts on the best way to tackle this?

@eddeee888 eddeee888 self-assigned this Jul 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants