From 90183bed6cbcef428f429066eb879f0bca89f831 Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 2 Oct 2026 10:25:56 +0000 Subject: [PATCH] =?UTF-8?q?test:=20reproduce=20#11026=20=E2=80=94=20nested?= =?UTF-8?q?=20fragment=20import=20dropped=20with=20omitOperationSuffix=20+?= =?UTF-8?q?=20combine?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_019G21LchfGxeMbf2U5bR6cL eddeee888:oss:issue-verify --- .../typescript/operations/package.json | 1 + .../tests/fixtures/issue-11026/markdown.ts | 8 ++ .../tests/fixtures/issue-11026/op.ts | 19 +++ .../ts-documents.near-operation-file.spec.ts | 68 ++++++++++ pnpm-lock.yaml | 121 +++++++++--------- 5 files changed, 153 insertions(+), 64 deletions(-) create mode 100644 packages/plugins/typescript/operations/tests/fixtures/issue-11026/markdown.ts create mode 100644 packages/plugins/typescript/operations/tests/fixtures/issue-11026/op.ts create mode 100644 packages/plugins/typescript/operations/tests/ts-documents.near-operation-file.spec.ts diff --git a/packages/plugins/typescript/operations/package.json b/packages/plugins/typescript/operations/package.json index 8aa09e2d877..7ee92968518 100644 --- a/packages/plugins/typescript/operations/package.json +++ b/packages/plugins/typescript/operations/package.json @@ -53,6 +53,7 @@ "tslib": "^2.8.0" }, "devDependencies": { + "@graphql-codegen/near-operation-file-preset": "5.2.2", "graphql-sock": "1.0.1" }, "publishConfig": { diff --git a/packages/plugins/typescript/operations/tests/fixtures/issue-11026/markdown.ts b/packages/plugins/typescript/operations/tests/fixtures/issue-11026/markdown.ts new file mode 100644 index 00000000000..2fabae1c68c --- /dev/null +++ b/packages/plugins/typescript/operations/tests/fixtures/issue-11026/markdown.ts @@ -0,0 +1,8 @@ +/* eslint-disable @typescript-eslint/ban-ts-comment */ + +//@ts-ignore +export const MarkdownFragment = gql(/* GraphQL */ ` + fragment MarkdownFragment on Markdown { + markdown + } +`); diff --git a/packages/plugins/typescript/operations/tests/fixtures/issue-11026/op.ts b/packages/plugins/typescript/operations/tests/fixtures/issue-11026/op.ts new file mode 100644 index 00000000000..80674d4deeb --- /dev/null +++ b/packages/plugins/typescript/operations/tests/fixtures/issue-11026/op.ts @@ -0,0 +1,19 @@ +/* eslint-disable @typescript-eslint/ban-ts-comment */ + +//@ts-ignore +export const WidgetFragment = gql(/* GraphQL */ ` + fragment WidgetFragment on Widget { + title { + ...MarkdownFragment + } + } +`); + +//@ts-ignore +export const PingQuery = gql(/* GraphQL */ ` + query Ping { + ping { + ...WidgetFragment + } + } +`); diff --git a/packages/plugins/typescript/operations/tests/ts-documents.near-operation-file.spec.ts b/packages/plugins/typescript/operations/tests/ts-documents.near-operation-file.spec.ts new file mode 100644 index 00000000000..09580e05d29 --- /dev/null +++ b/packages/plugins/typescript/operations/tests/ts-documents.near-operation-file.spec.ts @@ -0,0 +1,68 @@ +import path from 'path'; +import { executeCodegen } from '@graphql-codegen/cli'; +import * as nearOperationFilePreset from '@graphql-codegen/near-operation-file-preset'; +import * as typescriptOperationsPlugin from '../src/index.js'; + +const fixturesDir = path.join(__dirname, 'fixtures/issue-11026'); + +const runCodegen = (omitOperationSuffix: boolean) => + executeCodegen({ + cwd: fixturesDir, + schema: /* GraphQL */ ` + type Query { + ping: Widget + } + + type Widget { + title: Markdown + } + + type Markdown { + markdown: String + } + `, + documents: ['markdown.ts', 'op.ts'], + pluginLoader: async name => { + if (name === '@graphql-codegen/typescript-operations') { + return typescriptOperationsPlugin; + } + return import(name); + }, + generates: { + './': { + preset: nearOperationFilePreset, + presetConfig: { + extension: '.generated.ts', + baseTypesPath: 'globalTypes.ts', + }, + plugins: ['typescript-operations'], + config: { + omitOperationSuffix, + inlineFragmentTypes: 'combine', + }, + }, + }, + }); + +describe('TypeScript Operations Plugin - near-operation-file preset', () => { + it('Issue #11026 - imports fragment used by another fragment in the same file when omitOperationSuffix=true', async () => { + const { result } = await runCodegen(true); + + const opFile = result.find(file => file.filename.endsWith('op.generated.ts')); + expect(opFile.content).toContain( + `export type WidgetFragment = { title: MarkdownFragment | null };`, + ); + expect(opFile.content).toMatch( + /import (type )?\{ MarkdownFragment \} from '\.\/markdown\.generated';/, + ); + }); + + it('control: imports fragment used by another fragment in the same file when omitOperationSuffix=false', async () => { + const { result } = await runCodegen(false); + + const opFile = result.find(file => file.filename.endsWith('op.generated.ts')); + expect(opFile.content).toMatch( + /import (type )?\{ MarkdownFragmentFragment \} from '\.\/markdown\.generated';/, + ); + }); +}); diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 381890a852d..0fb73f35ca4 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -309,7 +309,7 @@ importers: version: 24.12.4 tsup: specifier: 8.5.1 - version: 8.5.1(@swc/core@1.15.33)(jiti@2.7.0)(postcss@8.5.14)(supports-color@10.2.2)(tsx@4.22.0)(typescript@6.0.3)(yaml@2.9.0) + version: 8.5.1(@swc/core@1.15.33)(jiti@2.7.0)(postcss@8.5.28)(supports-color@10.2.2)(tsx@4.22.0)(typescript@6.0.3)(yaml@2.9.0) examples/react/apollo-client: dependencies: @@ -1328,6 +1328,9 @@ importers: specifier: ^2.8.0 version: 2.8.1 devDependencies: + '@graphql-codegen/near-operation-file-preset': + specifier: 5.2.2 + version: 5.2.2(graphql@17.0.2) graphql-sock: specifier: 1.0.1 version: 1.0.1(graphql@17.0.2) @@ -3129,6 +3132,12 @@ packages: peerDependencies: graphql: 17.0.2 + '@graphql-codegen/near-operation-file-preset@5.2.2': + resolution: {integrity: sha512-12n7ZEiLZiMo4bAimviKVAB+5dX77/Vl4Vl7gclwqFmZqRVCej2ed+yYT1JhxnmcxTrQIJUAXAjRV5ehz0ak/Q==} + engines: {node: '>= 16.0.0'} + peerDependencies: + graphql: 17.0.2 + '@graphql-codegen/plugin-helpers@2.7.2': resolution: {integrity: sha512-kln2AZ12uii6U59OQXdjLk5nOlh1pHis1R98cDZGFnfaiAbX9V3fxcZ1MMJkB7qFUymTALzyjZoXXdyVmPMfRg==} peerDependencies: @@ -3145,8 +3154,8 @@ packages: peerDependencies: graphql: 17.0.2 - '@graphql-codegen/plugin-helpers@7.0.1': - resolution: {integrity: sha512-S2X0YT3XQbP2haqhIeku8GOXo2j8QuBu7BrLsOEHz4UeMu78y3rja1Q4ri3oJ0jq4dMgaQlazoVHI/A+FAKMGw==} + '@graphql-codegen/plugin-helpers@7.4.0': + resolution: {integrity: sha512-yRvRKsaa3EZMVmrBoOfTbiorGD6D1K459hE7h78/ROsw2jaBPQI3uN/3lG90skZAT+9KuD2roaIbOh+HGpPu7Q==} engines: {node: '>=16'} peerDependencies: graphql: 17.0.2 @@ -3313,8 +3322,8 @@ packages: peerDependencies: graphql: 17.0.2 - '@graphql-codegen/visitor-plugin-common@7.0.2': - resolution: {integrity: sha512-3v1dPjkSiAIsqwZ/6btSZ6BCYlYYpr3FdLhsBZ/JoPP2hYgN6AlGKdUyhYm5FsgDKU04L7al3+rfnTOCxqM0gw==} + '@graphql-codegen/visitor-plugin-common@7.2.7': + resolution: {integrity: sha512-sksmdldREXXA65dxO1/VZi5AjnawH/KFR0q1YqKNa5C3hSFgsWUkQ4i+ztXn3CMmixOUS8oPN04kz/qlBqbaZw==} engines: {node: '>=16'} peerDependencies: graphql: 17.0.2 @@ -7932,11 +7941,6 @@ packages: mz@2.7.0: resolution: {integrity: sha512-z81GNO7nnYMEhrGh9LeymoE4+Yr0Wn5McHIZMK5cfQCl+NDX08sCZgUc9/6MHni9IWuFLm1Z3HTCXu2z9fN62Q==} - nanoid@3.3.12: - resolution: {integrity: sha512-ZB9RH/39qpq5Vu6Y+NmUaFhQR6pp+M2Xt76XBnEwDaGcVAqhlvxrl3B2bKS5D3NH3QR76v3aSrKaF/Kiy7lEtQ==} - engines: {node: ^10 || ^12 || ^13.7 || ^14 || >=15.0.1} - hasBin: true - nanoid@3.3.19: resolution: {integrity: sha512-Y2tUNy4ouw6tq5oDSKeQYGOyhkUBhNOcGV/02KC+6kd9eDGqdZd++mjMiIDilrBYvjEnCYvVtsuHCuP+okSfug==} engines: {node: ^10 || ^12 || ^13.7 || ^14 || >=15.0.1} @@ -8349,10 +8353,6 @@ packages: resolution: {integrity: sha512-PS08Iboia9mts/2ygV3eLpY5ghnUcfLV/EXTOW1E2qYxJKGGBUtNjN76FYHnMs36RmARn41bC0AZmn+rR0OVpQ==} engines: {node: ^10 || ^12 || >=14} - postcss@8.5.14: - resolution: {integrity: sha512-SoSL4+OSEtR99LHFZQiJLkT59C5B1amGO1NzTwj7TT1qCUgUO6hxOvzkOYxD+vMrXBM3XJIKzokoERdqQq/Zmg==} - engines: {node: ^10 || ^12 || >=14} - postcss@8.5.28: resolution: {integrity: sha512-RRuzqDtt5Y9h3quz5hWhK+TPnsmVs6WwSU6LkJMeY4HstUEDuYTG8UJSdawMRzmzAtV+KEoG8N3Qg2qLy5vM/A==} engines: {node: ^10 || ^12 || >=14} @@ -9199,10 +9199,6 @@ packages: resolution: {integrity: sha512-dAqSqE/RabpBKI8+h26GfLq6Vb3JVXs30XYQjdMjaj/c2tS8IYYMbIzP599KtRj7c57/wYApb3QjgRgXmrCukA==} engines: {node: '>=18'} - tinyglobby@0.2.16: - resolution: {integrity: sha512-pn99VhoACYR8nFHhxqix+uvsbXineAasWm5ojXoN8xEwK5Kd3/TrhNn1wByuD52UxWRLy8pu+kRMniEi6Eq9Zg==} - engines: {node: '>=12.0.0'} - tinyglobby@0.2.17: resolution: {integrity: sha512-wXR/dYpcqKmfWpEdZjiKJOwCNFndD0DMnrW/cYjVGttEkBfVgcLFHoNrlj47mjOVic9yyNu65alsgF4NQyTa2g==} engines: {node: '>=12.0.0'} @@ -11937,7 +11933,7 @@ snapshots: '@graphql-codegen/add@7.0.0(graphql@17.0.2)': dependencies: - '@graphql-codegen/plugin-helpers': 7.0.1(graphql@17.0.2) + '@graphql-codegen/plugin-helpers': 7.4.0(graphql@17.0.2) graphql: 17.0.2 tslib: 2.8.1 @@ -12104,8 +12100,18 @@ snapshots: '@graphql-codegen/near-operation-file-preset@5.2.1(graphql@17.0.2)': dependencies: '@graphql-codegen/add': 7.0.0(graphql@17.0.2) - '@graphql-codegen/plugin-helpers': 7.0.1(graphql@17.0.2) - '@graphql-codegen/visitor-plugin-common': 7.0.2(graphql@17.0.2) + '@graphql-codegen/plugin-helpers': 7.4.0(graphql@17.0.2) + '@graphql-codegen/visitor-plugin-common': 7.2.7(graphql@17.0.2) + '@graphql-tools/utils': 11.2.0(graphql@17.0.2) + graphql: 17.0.2 + parse-filepath: 1.0.2 + tslib: 2.8.1 + + '@graphql-codegen/near-operation-file-preset@5.2.2(graphql@17.0.2)': + dependencies: + '@graphql-codegen/add': 7.0.0(graphql@17.0.2) + '@graphql-codegen/plugin-helpers': 7.4.0(graphql@17.0.2) + '@graphql-codegen/visitor-plugin-common': 7.2.7(graphql@17.0.2) '@graphql-tools/utils': 11.2.0(graphql@17.0.2) graphql: 17.0.2 parse-filepath: 1.0.2 @@ -12140,7 +12146,7 @@ snapshots: import-from: 4.0.0 tslib: 2.8.1 - '@graphql-codegen/plugin-helpers@7.0.1(graphql@17.0.2)': + '@graphql-codegen/plugin-helpers@7.4.0(graphql@17.0.2)': dependencies: '@graphql-tools/utils': 11.2.0(graphql@17.0.2) change-case-all: 2.1.0 @@ -12409,9 +12415,9 @@ snapshots: parse-filepath: 1.0.2 tslib: 2.8.1 - '@graphql-codegen/visitor-plugin-common@7.0.2(graphql@17.0.2)': + '@graphql-codegen/visitor-plugin-common@7.2.7(graphql@17.0.2)': dependencies: - '@graphql-codegen/plugin-helpers': 7.0.1(graphql@17.0.2) + '@graphql-codegen/plugin-helpers': 7.4.0(graphql@17.0.2) '@graphql-tools/optimize': 2.0.0(graphql@17.0.2) '@graphql-tools/relay-operation-optimizer': 7.1.4(graphql@17.0.2) '@graphql-tools/utils': 11.2.0(graphql@17.0.2) @@ -12769,7 +12775,7 @@ snapshots: '@hasparus/eslint-plugin-tailwindcss@3.17.5(tailwindcss@3.4.19(tsx@4.22.0)(yaml@2.9.0))': dependencies: fast-glob: 3.3.3 - postcss: 8.5.14 + postcss: 8.5.28 tailwindcss: 3.4.19(tsx@4.22.0)(yaml@2.9.0) '@humanfs/core@0.19.2': @@ -13998,7 +14004,7 @@ snapshots: debug: 4.4.3(supports-color@10.2.2) minimatch: 10.2.5 semver: 7.8.0 - tinyglobby: 0.2.16 + tinyglobby: 0.2.17 ts-api-utils: 2.5.0(typescript@6.0.3) typescript: 6.0.3 transitivePeerDependencies: @@ -14266,7 +14272,7 @@ snapshots: '@vue/shared': 3.5.34 estree-walker: 2.0.2 magic-string: 0.30.21 - postcss: 8.5.14 + postcss: 8.5.28 source-map-js: 1.2.1 '@vue/compiler-ssr@3.5.34': @@ -15587,7 +15593,7 @@ snapshots: get-tsconfig: 4.14.0 is-bun-module: 2.0.0 stable-hash: 0.0.5 - tinyglobby: 0.2.16 + tinyglobby: 0.2.17 unrs-resolver: 1.11.1 optionalDependencies: eslint-plugin-import: 2.32.0(@typescript-eslint/parser@8.59.3(eslint@10.4.0(jiti@2.7.0)(supports-color@10.2.2))(supports-color@10.2.2)(typescript@6.0.3))(eslint-import-resolver-typescript@3.10.1)(eslint@10.4.0(jiti@2.7.0)(supports-color@10.2.2))(supports-color@10.2.2) @@ -15601,7 +15607,7 @@ snapshots: get-tsconfig: 4.14.0 rspack-resolver: 1.3.0 stable-hash: 0.0.5 - tinyglobby: 0.2.16 + tinyglobby: 0.2.17 optionalDependencies: eslint-plugin-import: 2.31.0(@typescript-eslint/parser@8.59.3(eslint@10.4.0(jiti@2.7.0)(supports-color@10.2.2))(supports-color@10.2.2)(typescript@6.0.3))(eslint-import-resolver-typescript@4.2.1)(eslint@10.4.0(jiti@2.7.0)(supports-color@10.2.2))(supports-color@10.2.2) is-bun-module: 2.0.0 @@ -17583,8 +17589,6 @@ snapshots: object-assign: 4.1.1 thenify-all: 1.6.0 - nanoid@3.3.12: {} - nanoid@3.3.19: {} napi-postinstall@0.3.4: {} @@ -17946,30 +17950,30 @@ snapshots: possible-typed-array-names@1.1.0: {} - postcss-import@15.1.0(postcss@8.5.14): + postcss-import@15.1.0(postcss@8.5.28): dependencies: - postcss: 8.5.14 + postcss: 8.5.28 postcss-value-parser: 4.2.0 read-cache: 1.0.0 resolve: 1.22.12 - postcss-js@4.1.0(postcss@8.5.14): + postcss-js@4.1.0(postcss@8.5.28): dependencies: camelcase-css: 2.0.1 - postcss: 8.5.14 + postcss: 8.5.28 - postcss-load-config@6.0.1(jiti@2.7.0)(postcss@8.5.14)(tsx@4.22.0)(yaml@2.9.0): + postcss-load-config@6.0.1(jiti@2.7.0)(postcss@8.5.28)(tsx@4.22.0)(yaml@2.9.0): dependencies: lilconfig: 3.1.3 optionalDependencies: jiti: 2.7.0 - postcss: 8.5.14 + postcss: 8.5.28 tsx: 4.22.0 yaml: 2.9.0 - postcss-nested@6.2.0(postcss@8.5.14): + postcss-nested@6.2.0(postcss@8.5.28): dependencies: - postcss: 8.5.14 + postcss: 8.5.28 postcss-selector-parser: 6.1.2 postcss-selector-parser@6.1.2: @@ -17981,13 +17985,7 @@ snapshots: postcss@8.4.31: dependencies: - nanoid: 3.3.12 - picocolors: 1.1.1 - source-map-js: 1.2.1 - - postcss@8.5.14: - dependencies: - nanoid: 3.3.12 + nanoid: 3.3.19 picocolors: 1.1.1 source-map-js: 1.2.1 @@ -18858,7 +18856,7 @@ snapshots: lines-and-columns: 1.2.4 mz: 2.7.0 pirates: 4.0.7 - tinyglobby: 0.2.16 + tinyglobby: 0.2.17 ts-interface-checker: 0.1.13 supports-color@10.2.2: {} @@ -18951,11 +18949,11 @@ snapshots: normalize-path: 3.0.0 object-hash: 3.0.0 picocolors: 1.1.1 - postcss: 8.5.14 - postcss-import: 15.1.0(postcss@8.5.14) - postcss-js: 4.1.0(postcss@8.5.14) - postcss-load-config: 6.0.1(jiti@2.7.0)(postcss@8.5.14)(tsx@4.22.0)(yaml@2.9.0) - postcss-nested: 6.2.0(postcss@8.5.14) + postcss: 8.5.28 + postcss-import: 15.1.0(postcss@8.5.28) + postcss-js: 4.1.0(postcss@8.5.28) + postcss-load-config: 6.0.1(jiti@2.7.0)(postcss@8.5.28)(tsx@4.22.0)(yaml@2.9.0) + postcss-nested: 6.2.0(postcss@8.5.28) postcss-selector-parser: 6.1.2 resolve: 1.22.12 sucrase: 3.35.1 @@ -18991,11 +18989,6 @@ snapshots: tinyexec@1.1.2: {} - tinyglobby@0.2.16: - dependencies: - fdir: 6.5.0(picomatch@4.0.4) - picomatch: 4.0.4 - tinyglobby@0.2.17: dependencies: fdir: 6.5.0(picomatch@4.0.4) @@ -19096,7 +19089,7 @@ snapshots: tslib@2.8.1: {} - tsup@8.5.1(@swc/core@1.15.33)(jiti@2.7.0)(postcss@8.5.14)(supports-color@10.2.2)(tsx@4.22.0)(typescript@6.0.3)(yaml@2.9.0): + tsup@8.5.1(@swc/core@1.15.33)(jiti@2.7.0)(postcss@8.5.28)(supports-color@10.2.2)(tsx@4.22.0)(typescript@6.0.3)(yaml@2.9.0): dependencies: bundle-require: 5.1.0(esbuild@0.27.7) cac: 6.7.14 @@ -19107,17 +19100,17 @@ snapshots: fix-dts-default-cjs-exports: 1.0.1 joycon: 3.1.1 picocolors: 1.1.1 - postcss-load-config: 6.0.1(jiti@2.7.0)(postcss@8.5.14)(tsx@4.22.0)(yaml@2.9.0) + postcss-load-config: 6.0.1(jiti@2.7.0)(postcss@8.5.28)(tsx@4.22.0)(yaml@2.9.0) resolve-from: 5.0.0 rollup: 4.60.4 source-map: 0.7.6 sucrase: 3.35.1 tinyexec: 0.3.2 - tinyglobby: 0.2.16 + tinyglobby: 0.2.17 tree-kill: 1.2.2 optionalDependencies: '@swc/core': 1.15.33 - postcss: 8.5.14 + postcss: 8.5.28 typescript: 6.0.3 transitivePeerDependencies: - jiti @@ -19440,9 +19433,9 @@ snapshots: dependencies: lightningcss: 1.32.0 picomatch: 4.0.4 - postcss: 8.5.14 + postcss: 8.5.28 rolldown: 1.0.1 - tinyglobby: 0.2.16 + tinyglobby: 0.2.17 optionalDependencies: '@types/node': 24.12.4 esbuild: 0.28.0 @@ -19484,7 +19477,7 @@ snapshots: std-env: 4.1.0 tinybench: 2.9.0 tinyexec: 1.1.2 - tinyglobby: 0.2.16 + tinyglobby: 0.2.17 tinyrainbow: 3.1.0 vite: 8.0.16(@types/node@24.12.4)(esbuild@0.28.0)(jiti@2.7.0)(tsx@4.22.0)(yaml@2.9.0) why-is-node-running: 2.3.0