dotansimha / graphql-code-generator-community

MIT License
113 stars 144 forks source link

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

Open rushelex opened 1 month ago

rushelex commented 1 month 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 6 days ago

I experienced the same issue. The option useTypeImports is buggy