dotansimha / dotansimha/graphql-code-generator-community
Graphql-request (5.0.0) fetcher generates invalid types
- Dominant language
- TypeScript
- Stars
- 137
- Forks
- 195
- Avg merge
- 6h 20m
- Merged PRs (30d)
- 16
Description
### Describe the bug
When using graphql-request as the fetcher the generated getcher code has typescript errors. This did not happin in Graphql-request (4.X.X).
The generated code with issues is as follows:
```typescript
function fetcher(client: GraphQLClient, query: string, variables?: TVariables, headers?: RequestInit['headers']) {
return async (): Promise => client.request(query, variables, headers);
}
```
The tsc error that it gives is:
```
Error:(12, 79) TS2345: Argument of type '[TVariables | undefined, HeadersInit | undefined]' is not assignable to parameter of type 'TVariables extends Record ? [variables?: TVariables | undefined, requestHeaders?: HeadersInit | undefined] : keyof RemoveIndex extends never ? [variables?: ...] : [variables: ...]'.
```
### Your Example Website or App
local repo
### Steps to Reproduce the Bug or Issue
Use the following codegen.ts
```
import { CodegenConfig } from '@graphql-codegen/cli';
const config: CodegenConfig = {
schema: {
'https://SCHEMA-URL': {
headers: {
}
}
},
documents: 'src/graphql/*.graphql',
generates: {
'./graphql.schema.json': {
plugins: ['introspection']
},
'src/@types/graphql.types.ts': {
plugins: ['typescript', 'typescript-operations', 'typescript-react-query', 'typescript-document-nodes'],
config: {
skipTypename: true,
typesPrefix: 'Gql',
fetcher: 'graphql-request',
namePrefix: 'Dn'
}
}
}
};
export default config;
```
You will get the error
### Expected behavior
I would expect that the generated graphql.types.ts would not have typescript errors
### Screenshots or Videos
_No response_
### Platform
- OS: Linux
- NodeJS: 14.X
- `graphql` version: 16.6.0
"@graphql-codegen/cli": "2.12.0",
"@graphql-codegen/introspection": "2.2.1",
"@graphql-codegen/typescript": "2.7.3",
"@graphql-codegen/typescript-document-nodes": "2.3.3",
"@graphql-codegen/typescript-operations": "2.5.3",
"@graphql-codegen/typescript-react-query": "^4.0.1",
### Codegen Config File
```
import { CodegenConfig } from '@graphql-codegen/cli';
const config: CodegenConfig = {
schema: {
'https://SCHEMA-URL': {
headers: {
}
}
},
documents: 'src/graphql/*.graphql',
generates: {
'./graphql.schema.json': {
plugins: ['introspection']
},
'src/@types/graphql.types.ts': {
plugins: ['typescript', 'typescript-operations', 'typescript-react-query', 'typescript-document-nodes'],
config: {
skipTypename: true,
typesPrefix: 'Gql',
fetcher: 'graphql-request',
namePrefix: 'Dn'
}
}
}
};
export default config;
```
### Additional context
...
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.