From 71f7c7654b1a788ed9e86b29cb00185fd227fe80 Mon Sep 17 00:00:00 2001 From: wassim-k Date: Mon, 29 Jun 2026 11:46:54 +1000 Subject: [PATCH] fix: `generateImportStatement` emits invalid `import * from '...'` --- .changeset/empty-fragment-import.md | 5 +++++ packages/plugins/other/visitor-plugin-common/src/imports.ts | 4 ++++ 2 files changed, 9 insertions(+) create mode 100644 .changeset/empty-fragment-import.md diff --git a/.changeset/empty-fragment-import.md b/.changeset/empty-fragment-import.md new file mode 100644 index 00000000000..46040b5e770 --- /dev/null +++ b/.changeset/empty-fragment-import.md @@ -0,0 +1,5 @@ +--- +'@graphql-codegen/visitor-plugin-common': patch +--- + +Avoid emitting an empty import statement (`import '...';`) when an import source has no identifiers and no namespace. diff --git a/packages/plugins/other/visitor-plugin-common/src/imports.ts b/packages/plugins/other/visitor-plugin-common/src/imports.ts index 8ac5fc27254..2d506d6f423 100644 --- a/packages/plugins/other/visitor-plugin-common/src/imports.ts +++ b/packages/plugins/other/visitor-plugin-common/src/imports.ts @@ -55,6 +55,10 @@ export function generateFragmentImportStatement( export function generateImportStatement(statement: ImportDeclaration): string { const { baseDir, importSource, outputPath, typesImport } = statement; + + if (!importSource.identifiers?.length && !importSource.namespace) { + return ''; + } const importPath = resolveImportPath(baseDir, outputPath, importSource.path); const importNames = importSource.identifiers?.length ? `{ ${Array.from(new Set(importSource.identifiers)).join(', ')} }`