dotansimha / graphql-code-generator-community

MIT License
112 stars 143 forks source link

typescript-graphql-request generated code uses GraphQLError without importing it #458

Closed yshrsmz closed 10 months ago

yshrsmz commented 11 months ago

Which packages are impacted by your issue?

@graphql-codegen/typescript-graphql-request

Describe the bug

Generated code uses GraphQLError without importing it.

Your Example Website or App

https://stackblitz.com/edit/github-jjt8y7?file=types.ts%3AL61

Steps to Reproduce the Bug or Issue

Please refer to the types.ts in the repro. In line 62, you can see GraphQLError used but no import for it.

Expected behavior

There should be a import statement for GraphQLError

Screenshots or Videos

スクリーンショット 2023-10-19 0 54 47

Platform

Codegen Config File

import { CodegenConfig } from '@graphql-codegen/cli';

const config: CodegenConfig = {
  schema: 'schema.graphql',
  documents: 'document.graphql',
  generates: {
    'types.ts': {
      plugins: [
        'typescript',
        'typescript-operations',
        'typescript-graphql-request',
      ],
      config: {
        rawRequest: true,
      },
    },
  },
};

export default config;

Additional context

No response

yshrsmz commented 10 months ago

In the meantime we can use add plugin to prepend the import statement.

      plugins: [
        'typescript-operations',
        'typescript-graphql-request',
        {
          add: {
            content: [
              '/* eslint-disable */',
              `import type { GraphQLError } from 'graphql'`,
            ],
          },
        },
      ],
saihaj commented 10 months ago

@graphql-codegen/typescript-graphql-request@6.0.1