dotansimha / dotansimha/graphql-code-generator-community

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

Open
#824 4 comments 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
137
Forks
195
Avg merge
6h 20m
Merged PRs (30d)
16

Description

### 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

- OS: macOS
- NodeJS: 18.19.0
- `graphql` version: 16.9.0
- `@graphql-codegen/typescript-react-query` version: 6.1.0

### Codegen Config File

```typescript
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_

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.