-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Open
Description
Which packages are impacted by your issue?
@graphql-codegen/typed-document-node
Describe the bug
When using typed-document-node@6.1.0+ with the import-types preset, the generated code incorrectly adds a Types. prefix to all DocumentNode result types, including fragments. This causes TypeScript compilation errors because:
- Operation types come from the external
Typesnamespace (correct) - Fragment types are generated locally and should NOT be prefixed (but they are)
Root Cause
In PR #10456 (commit 655b91d), the typed-document-node plugin added the importOperationTypesFrom feature. The implementation indiscriminately applies the Types. prefix to ALL non-unknown result types without distinguishing between:
- Operations (should be prefixed - they come from external Types namespace)
- Fragments (should NOT be prefixed - they're generated locally)
Source: visitor.ts lines 101-103:
const resultImportPrefix = shouldUseImportPrefix && resultType !== 'unknown' ? 'Types.' : '';Your Example Website or App
https://github.com/pachuka/-graphql-codegen-typed-document-node-fragment-namespace-bug
Steps to Reproduce the Bug or Issue
- Pull down the reproduction repo
- npm install
- npm run codegen
- npm run build // should fail
- update package.json to downgrade @graphql-codegen/typed-document-node to 6.0.2
- repeat steps 2-4 (build should pass)
Expected behavior
Fragments should not be prefixed with the Types namespace when used w/import-types preset.
Screenshots or Videos
No response
Platform
- OS: macOS
- NodeJS: 24.7.0
graphqlversion: 16.12.0@graphql-codegen/typed-document-nodeversion(s): 6.1.0+
Codegen Config File
overwrite: true
schema: schema.graphql
documents: operations.graphql
generates:
generated.ts:
preset: import-types
presetConfig:
typesPath: ./types
plugins:
- typescript
- typescript-operations
- typed-document-node
config:
scalars:
DateTime: Date
namingConvention:
typeNames: change-case#pascalCase
enumValues: change-case#upperCase
types.ts:
plugins:
- typescript
config:
scalars:
DateTime: DateAdditional context
No response
eddeee888
Metadata
Metadata
Assignees
Labels
No labels