Graphql-request (5.0.0) fetcher generates invalid types
See original GitHub issueDescribe 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:
function fetcher<TData, TVariables>(client: GraphQLClient, query: string, variables?: TVariables, headers?: RequestInit['headers']) {
return async (): Promise<TData> => client.request<TData, TVariables>(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<any, never> ? [variables?: TVariables | undefined, requestHeaders?: HeadersInit | undefined] : keyof RemoveIndex<TVariables> 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
…
Issue Analytics
- State:
- Created a year ago
- Reactions:8
- Comments:14 (1 by maintainers)
Top Results From Across the Web
react-query plugin with graphql-request fetcher generates ...
The latest version introduces an issue where, if an infinite query has no arguments, the react-query plugin generates invalid types. Your ...
Read more >graphql-code-generator - Bountysource
The latest version introduces an issue where, if an infinite query has no arguments, the react-query plugin generates invalid types. Your Example Website...
Read more >Invalid Syntax error while consuming graphql API
meanwhile I tried to implement 1 simple one without any input type Query{reportFormats : [ReportOutputFormat]} type ReportOutputFormat{ id : ...
Read more >Testing - DGS Framework - Netflix Open Source
Create a test class with the following contents to test the ShowsDatafetcher from the getting started example. Java Kotlin. import com.
Read more >graphql-request - npm
Minimal GraphQL client supporting Node and browsers for scripts or simple apps. Latest version: 5.1.0, last published: 9 days ago.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
This doesn’t seem right. @GimpMaster uses
typescript-react-query
as his plugin for code generation, while the fix is fortypescript-graphql-request
, which is a different one. From what I see and tried, doesn’t seem like it solved the initial issue withtypescript-react-query
. Or am I missing something?@GimpMaster @Zerebokep, I can confirm that the issue is solved when using
graphql-request@next