Skip to content

Commit ad8258c

Browse files
pentlakazuki watanabe
andauthored
fix(typescript-graphql-request): Fix typescript error (#549)
* Fix typescript error on graphql-request on v6.1.0 * Add changeset --------- Co-authored-by: kazuki watanabe <[email protected]>
1 parent c2b4a1b commit ad8258c

3 files changed

Lines changed: 30 additions & 24 deletions

File tree

.changeset/hot-ravens-compare.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@graphql-codegen/typescript-graphql-request': minor
3+
---
4+
5+
Fix TypeScript error when moduleResolution is "nodenext" or "bundler"

packages/plugins/typescript/graphql-request/src/visitor.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,9 @@ export class GraphQLRequestVisitor extends ClientSideBaseVisitor<
4545
autoBind(this);
4646

4747
const typeImport = this.config.useTypeImports ? 'import type' : 'import';
48-
const fileExtension = this.config.emitLegacyCommonJSImports ? '' : '.js';
49-
const buildPath = this.config.emitLegacyCommonJSImports ? 'cjs' : 'esm';
5048

51-
this._additionalImports.push(`${typeImport} { GraphQLClient } from 'graphql-request';`);
5249
this._additionalImports.push(
53-
`${typeImport} { GraphQLClientRequestHeaders } from 'graphql-request/build/${buildPath}/types${fileExtension}';`,
50+
`${typeImport} { GraphQLClient, RequestOptions } from 'graphql-request';`,
5451
);
5552

5653
if (this.config.rawRequest) {
@@ -61,6 +58,10 @@ export class GraphQLRequestVisitor extends ClientSideBaseVisitor<
6158
}
6259
}
6360

61+
this._additionalImports.push(
62+
`type GraphQLClientRequestHeaders = RequestOptions['requestHeaders'];`,
63+
);
64+
6465
this._externalImportPrefix = this.config.importOperationTypesFrom
6566
? `${this.config.importOperationTypesFrom}.`
6667
: '';

packages/plugins/typescript/graphql-request/tests/__snapshots__/graphql-request.spec.ts.snap

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ export type InputMaybe<T> = Maybe<T>;
66
export type Exact<T extends { [key: string]: unknown }> = { [K in keyof T]: T[K] };
77
export type MakeOptional<T, K extends keyof T> = Omit<T, K> & { [SubKey in K]?: Maybe<T[SubKey]> };
88
export type MakeMaybe<T, K extends keyof T> = Omit<T, K> & { [SubKey in K]: Maybe<T[SubKey]> };
9-
import { GraphQLClient } from 'graphql-request';
10-
import { GraphQLClientRequestHeaders } from 'graphql-request/build/cjs/types';
9+
import { GraphQLClient, RequestOptions } from 'graphql-request';
10+
type GraphQLClientRequestHeaders = RequestOptions['requestHeaders'];
1111
/** All built-in and custom scalars, mapped to their actual values */
1212
export type Scalars = {
1313
ID: string;
@@ -291,8 +291,8 @@ export type InputMaybe<T> = Maybe<T>;
291291
export type Exact<T extends { [key: string]: unknown }> = { [K in keyof T]: T[K] };
292292
export type MakeOptional<T, K extends keyof T> = Omit<T, K> & { [SubKey in K]?: Maybe<T[SubKey]> };
293293
export type MakeMaybe<T, K extends keyof T> = Omit<T, K> & { [SubKey in K]: Maybe<T[SubKey]> };
294-
import { GraphQLClient } from 'graphql-request';
295-
import { GraphQLClientRequestHeaders } from 'graphql-request/build/cjs/types';
294+
import { GraphQLClient, RequestOptions } from 'graphql-request';
295+
type GraphQLClientRequestHeaders = RequestOptions['requestHeaders'];
296296
import gql from 'graphql-tag';
297297
/** All built-in and custom scalars, mapped to their actual values */
298298
export type Scalars = {
@@ -570,8 +570,8 @@ export type InputMaybe<T> = Maybe<T>;
570570
export type Exact<T extends { [key: string]: unknown }> = { [K in keyof T]: T[K] };
571571
export type MakeOptional<T, K extends keyof T> = Omit<T, K> & { [SubKey in K]?: Maybe<T[SubKey]> };
572572
export type MakeMaybe<T, K extends keyof T> = Omit<T, K> & { [SubKey in K]: Maybe<T[SubKey]> };
573-
import { GraphQLClient } from 'graphql-request';
574-
import { GraphQLClientRequestHeaders } from 'graphql-request/build/cjs/types';
573+
import { GraphQLClient, RequestOptions } from 'graphql-request';
574+
type GraphQLClientRequestHeaders = RequestOptions['requestHeaders'];
575575
/** All built-in and custom scalars, mapped to their actual values */
576576
export type Scalars = {
577577
ID: string;
@@ -848,9 +848,9 @@ export type InputMaybe<T> = Maybe<T>;
848848
export type Exact<T extends { [key: string]: unknown }> = { [K in keyof T]: T[K] };
849849
export type MakeOptional<T, K extends keyof T> = Omit<T, K> & { [SubKey in K]?: Maybe<T[SubKey]> };
850850
export type MakeMaybe<T, K extends keyof T> = Omit<T, K> & { [SubKey in K]: Maybe<T[SubKey]> };
851-
import type { GraphQLClient } from 'graphql-request';
852-
import type { GraphQLClientRequestHeaders } from 'graphql-request/build/cjs/types';
851+
import type { GraphQLClient, RequestOptions } from 'graphql-request';
853852
import { GraphQLError, print } from 'graphql'
853+
type GraphQLClientRequestHeaders = RequestOptions['requestHeaders'];
854854
import gql from 'graphql-tag';
855855
/** All built-in and custom scalars, mapped to their actual values */
856856
export type Scalars = {
@@ -1132,9 +1132,9 @@ export type InputMaybe<T> = Maybe<T>;
11321132
export type Exact<T extends { [key: string]: unknown }> = { [K in keyof T]: T[K] };
11331133
export type MakeOptional<T, K extends keyof T> = Omit<T, K> & { [SubKey in K]?: Maybe<T[SubKey]> };
11341134
export type MakeMaybe<T, K extends keyof T> = Omit<T, K> & { [SubKey in K]: Maybe<T[SubKey]> };
1135-
import { GraphQLClient } from 'graphql-request';
1136-
import { GraphQLClientRequestHeaders } from 'graphql-request/build/cjs/types';
1135+
import { GraphQLClient, RequestOptions } from 'graphql-request';
11371136
import { GraphQLError } from 'graphql'
1137+
type GraphQLClientRequestHeaders = RequestOptions['requestHeaders'];
11381138
/** All built-in and custom scalars, mapped to their actual values */
11391139
export type Scalars = {
11401140
ID: string;
@@ -1412,8 +1412,8 @@ export type InputMaybe<T> = Maybe<T>;
14121412
export type Exact<T extends { [key: string]: unknown }> = { [K in keyof T]: T[K] };
14131413
export type MakeOptional<T, K extends keyof T> = Omit<T, K> & { [SubKey in K]?: Maybe<T[SubKey]> };
14141414
export type MakeMaybe<T, K extends keyof T> = Omit<T, K> & { [SubKey in K]: Maybe<T[SubKey]> };
1415-
import { GraphQLClient } from 'graphql-request';
1416-
import { GraphQLClientRequestHeaders } from 'graphql-request/build/esm/types.js';
1415+
import { GraphQLClient, RequestOptions } from 'graphql-request';
1416+
type GraphQLClientRequestHeaders = RequestOptions['requestHeaders'];
14171417
import gql from 'graphql-tag';
14181418
/** All built-in and custom scalars, mapped to their actual values */
14191419
export type Scalars = {
@@ -1692,9 +1692,9 @@ export type InputMaybe<T> = Maybe<T>;
16921692
export type Exact<T extends { [key: string]: unknown }> = { [K in keyof T]: T[K] };
16931693
export type MakeOptional<T, K extends keyof T> = Omit<T, K> & { [SubKey in K]?: Maybe<T[SubKey]> };
16941694
export type MakeMaybe<T, K extends keyof T> = Omit<T, K> & { [SubKey in K]: Maybe<T[SubKey]> };
1695-
import { GraphQLClient } from 'graphql-request';
1696-
import { GraphQLClientRequestHeaders } from 'graphql-request/build/cjs/types';
1695+
import { GraphQLClient, RequestOptions } from 'graphql-request';
16971696
import { GraphQLError, print } from 'graphql'
1697+
type GraphQLClientRequestHeaders = RequestOptions['requestHeaders'];
16981698
import gql from 'graphql-tag';
16991699
/** All built-in and custom scalars, mapped to their actual values */
17001700
export type Scalars = {
@@ -1976,9 +1976,9 @@ export type InputMaybe<T> = Maybe<T>;
19761976
export type Exact<T extends { [key: string]: unknown }> = { [K in keyof T]: T[K] };
19771977
export type MakeOptional<T, K extends keyof T> = Omit<T, K> & { [SubKey in K]?: Maybe<T[SubKey]> };
19781978
export type MakeMaybe<T, K extends keyof T> = Omit<T, K> & { [SubKey in K]: Maybe<T[SubKey]> };
1979-
import { GraphQLClient } from 'graphql-request';
1980-
import { GraphQLClientRequestHeaders } from 'graphql-request/build/cjs/types';
1979+
import { GraphQLClient, RequestOptions } from 'graphql-request';
19811980
import { GraphQLError, print } from 'graphql'
1981+
type GraphQLClientRequestHeaders = RequestOptions['requestHeaders'];
19821982
import gql from 'graphql-tag';
19831983
/** All built-in and custom scalars, mapped to their actual values */
19841984
export type Scalars = {
@@ -2260,8 +2260,8 @@ export type InputMaybe<T> = Maybe<T>;
22602260
export type Exact<T extends { [key: string]: unknown }> = { [K in keyof T]: T[K] };
22612261
export type MakeOptional<T, K extends keyof T> = Omit<T, K> & { [SubKey in K]?: Maybe<T[SubKey]> };
22622262
export type MakeMaybe<T, K extends keyof T> = Omit<T, K> & { [SubKey in K]: Maybe<T[SubKey]> };
2263-
import type { GraphQLClient } from 'graphql-request';
2264-
import type { GraphQLClientRequestHeaders } from 'graphql-request/build/cjs/types';
2263+
import type { GraphQLClient, RequestOptions } from 'graphql-request';
2264+
type GraphQLClientRequestHeaders = RequestOptions['requestHeaders'];
22652265
import gql from 'graphql-tag';
22662266
/** All built-in and custom scalars, mapped to their actual values */
22672267
export type Scalars = {
@@ -2540,8 +2540,8 @@ export type InputMaybe<T> = Maybe<T>;
25402540
export type Exact<T extends { [key: string]: unknown }> = { [K in keyof T]: T[K] };
25412541
export type MakeOptional<T, K extends keyof T> = Omit<T, K> & { [SubKey in K]?: Maybe<T[SubKey]> };
25422542
export type MakeMaybe<T, K extends keyof T> = Omit<T, K> & { [SubKey in K]: Maybe<T[SubKey]> };
2543-
import { GraphQLClient } from 'graphql-request';
2544-
import { GraphQLClientRequestHeaders } from 'graphql-request/build/cjs/types';
2543+
import { GraphQLClient, RequestOptions } from 'graphql-request';
2544+
type GraphQLClientRequestHeaders = RequestOptions['requestHeaders'];
25452545
import gql from 'graphql-tag';
25462546
/** All built-in and custom scalars, mapped to their actual values */
25472547
export type Scalars = {

0 commit comments

Comments
 (0)