Closed the-simian closed 4 days ago
I believe this may be a duplicate issue of this solution, investigating: https://github.com/dotansimha/graphql-code-generator/issues/9595#issuecomment-1682041289
apologies if I jumped the gun here.
Ok that was it.
import type { CodegenConfig } from '@graphql-codegen/cli';
const config: CodegenConfig = {
//...other config
generates: {
'./db/__generated__/': {
plugins: ['typescript', 'typescript-resolvers'],
config: {
//... other config.
useTypeImports: true, //<--- this is the thing that fixes it.
},
},
}
export default config;
Which packages are impacted by your issue?
@graphql-codegen/cli, @graphql-codegen/typed-document-node
Describe the bug
import { TypedDocumentNode as DocumentNode } from '@graphql-typed-document-node/core';
will throw an errorTypedDocumentNode is a type and must be imported using a type-only import when verbatimModuleSyntax is enabled.
This can be fixed by changing the line to
import { type TypedDocumentNode as DocumentNode } from '@graphql-typed-document-node/core';
Your Example Website or App
https://github.com/dotansimha/graphql-code-generator
Steps to Reproduce the Bug or Issue
use this property and set it to true, which enforces stricter type checks in files, forcing the use of the keyword 'type' when something is a type
then run
graphql-codegen
, the output fails.Expected behavior
As a user I am expecting
import { type TypedDocumentNode as DocumentNode } from '@graphql-typed-document-node/core';
but I am seeingimport { TypedDocumentNode as DocumentNode } from '@graphql-typed-document-node/core';
the word 'type' is missing.
Screenshots or Videos
Platform
graphql
version: [e.g. 16.3.0]@graphql-codegen/*
version(s): [e.g. 2.6.2]Codegen Config File
No response
Additional context
Just put the word 'type' in the generated file and its fine!