dotansimha / graphql-code-generator-community

MIT License
119 stars 157 forks source link

`react-query` imports a custom fetcher as a type with `useTypeImports` enabled #824

Open rushelex opened 3 months ago

rushelex commented 3 months ago

Which packages are impacted by your issue?

@graphql-codegen/typescript-react-query

Describe the bug

When I specify fetcher option with a custom path to my function and useTypeImports with a value of true in the generation settings, the generated files import my function with the type import modifier, which causes TypeScript to fail and the application to build.

Your Example Website or App

https://stackblitz.com/edit/github-djwd6w?file=codegen.ts

Steps to Reproduce the Bug or Issue

  1. Go to reproduce
  2. Run npm run generate
  3. Go to types.ts file
  4. See on import of import type { fetcher } from './custom-fetcher'

Expected behavior

As a user I am expected that import path will be import { fetcher } from './custom-fetcher' with option useTypeImports: true, because fetcher is a function, but not type or interface.

Screenshots or Videos

No response

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',
        '@graphql-codegen/typescript-react-query',
      ],
      config: {
        reactQueryVersion: 5,
        fetcher: './custom-fetcher#fetcher',
        useTypeImports: true,
      },
    },
  },
};

export default config;

Additional context

No response

dohomi commented 2 months ago

I experienced the same issue. The option useTypeImports is buggy