Open nbouvrette opened 1 year ago
I just upgraded to version 4.0.0 and it looks like this issue is still occurring.
Any updates?
Any updates on this? I've had to add the following hack to my config file:
"typescript-react-query", { add: { content: "// @ts-nocheck", }, },
Which is far from ideal
Any updates here?
If you are using typescript-graphql-request
and not @graphql-codegen/typescript-graphql-request
then it's only compatible with graphql-request
up to 4.
diff --git a/node_modules/@graphql-codegen/typescript-react-query/cjs/fetcher-graphql-request.js b/node_modules/@graphql-codegen/typescript-react-query/cjs/fetcher-graphql-request.js
index 6476390..6bde16a 100644
--- a/node_modules/@graphql-codegen/typescript-react-query/cjs/fetcher-graphql-request.js
+++ b/node_modules/@graphql-codegen/typescript-react-query/cjs/fetcher-graphql-request.js
@@ -62,7 +62,6 @@ function fetcher<TData, TVariables extends { [key: string]: any }>(client: Graph
if (this.clientPath)
this.visitor.imports.add(this.clientPath);
this.visitor.imports.add(`${typeImport} { GraphQLClient } from 'graphql-request';`);
- this.visitor.imports.add(`${typeImport} { RequestInit } from 'graphql-request/dist/types.dom';`);
const { generateBaseQueryHook, variables, options } = this.generateQueryHelper(config, isSuspense);
const { documentVariableName, operationResultType, operationVariablesTypes } = config;
return this.clientPath
@@ -114,7 +113,6 @@ function fetcher<TData, TVariables extends { [key: string]: any }>(client: Graph
const typeImport = this.visitor.config.useTypeImports ? 'import type' : 'import';
if (this.clientPath)
this.visitor.imports.add(this.clientPath);
- this.visitor.imports.add(`${typeImport} { RequestInit } from 'graphql-request/dist/types.dom';`);
return this.clientPath
? `\nuse${operationName}.fetcher = (${variables}, headers?: RequestInit['headers']) => fetcher<${operationResultType}, ${operationVariablesTypes}>(${documentVariableName}, variables, headers);`
: `\nuse${operationName}.fetcher = (client: GraphQLClient, ${variables}, headers?: RequestInit['headers']) => fetcher<${operationResultType}, ${operationVariablesTypes}>(client, ${documentVariableName}, variables, headers);`;
Still not sure what to do here and how has this not been fixed after almost 2 years.
Which packages are impacted by your issue?
@graphql-codegen/typescript-operations, @graphql-codegen/typescript
Describe the bug
This is related to https://github.com/dotansimha/graphql-code-generator-community/issues/501 but the issue is different after updating to TypeScript 5.x
I used these packages versions from my package.json (also impacts version 4)
Also unlike the fix for issue dotansimha/graphql-code-generator-community#501, I do not use
@graphql-codegen/typescript-graphql-request
instead I installedgraphql-request
directly because we use it in our code. This is how the package looks like withnpm ls graphql-request
:This is a sample of our codegen config, which uses a
graphql-request
fetcher:When we run codegen, the generated files include the following problematic line:
Before TypeScript 5.x, the fix was to replace:
import { RequestInit } from 'graphql-request/dist/types.dom';
byimport { RequestInit } from 'graphql-request/src/types.dom';
(this is being discuss in dotansimha/graphql-code-generator-community#501)As soon as TypeScript is updated to 5.x then it is bundled with a
RequestInit
innode_modules/typescript/lib/lib.dom.d.ts
so the line becomes obsolete.The expected result would be that the generated file do not contain that line.
In fact, I am applying the current fix today to be able to build my application:
1) I added hooks in the codegen config
2) The script removing the line:
Platform
graphql-request
version: 6@graphql-codegen/*
version(s): 3.3.1