graphql-js icon indicating copy to clipboard operation
graphql-js copied to clipboard

Generator generates alias imports not compatible with TypeScript Type-Only Imports and verbatimModuleSyntax

Open lubos-bistak opened this issue 3 years ago • 2 comments

By running npx graphql-code-generator graphql.ts files are generated with imports

import {TypedDocumentNode as DocumentNode} from '@graphql-typed-document-node/core'

that are not compatible with TypeScript configuration

tsconfig.ts

"compilerOptions": {
    "verbatimModuleSyntax": true
}

It should be

import {type TypedDocumentNode as DocumentNode} from '@graphql-typed-document-node/core'

Documentation:

  • https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-8.html
  • https://www.typescriptlang.org/tsconfig#verbatimModuleSyntax

Is there any option to control how such imports are generated?

lubos-bistak avatar Aug 29 '23 06:08 lubos-bistak

@lubos-bistak graphql-code-generator is not part of this organization and is not related to this repo. Can you please open issue in graphql-code-generator repo

IvanGoncharov avatar Sep 01 '23 11:09 IvanGoncharov

This issue can be solved with

const config: CodegenConfig = {
  ...
  generates: {
    "src/gql/": {
      ...
      config: {
        useTypeImports: true
      },
    }
  }
};

also described in https://github.com/dotansimha/graphql-code-generator/issues/9595

lubos-bistak avatar Sep 04 '23 07:09 lubos-bistak