From f8271d6be37a4898ba64ae0a0a5b4b740cb0a976 Mon Sep 17 00:00:00 2001 From: Roel van Hintum Date: Thu, 16 Apr 2026 10:27:33 +0200 Subject: [PATCH] fix: import graphql-request RequestOptions as type --- .changeset/hot-eels-dig.md | 5 +++++ .../typescript/graphql-request/src/visitor.ts | 2 +- .../graphql-request.spec.ts.snap | 20 +++++++++---------- .../graphql-request.v16+.spec.ts.snap | 2 +- 4 files changed, 17 insertions(+), 12 deletions(-) create mode 100644 .changeset/hot-eels-dig.md diff --git a/.changeset/hot-eels-dig.md b/.changeset/hot-eels-dig.md new file mode 100644 index 0000000000..0f4d7f0286 --- /dev/null +++ b/.changeset/hot-eels-dig.md @@ -0,0 +1,5 @@ +--- +'@graphql-codegen/typescript-graphql-request': minor +--- + +Import graphql-request RequestOptions as a type diff --git a/packages/plugins/typescript/graphql-request/src/visitor.ts b/packages/plugins/typescript/graphql-request/src/visitor.ts index 69272fd4c6..d58a0f7787 100644 --- a/packages/plugins/typescript/graphql-request/src/visitor.ts +++ b/packages/plugins/typescript/graphql-request/src/visitor.ts @@ -48,7 +48,7 @@ export class GraphQLRequestVisitor extends ClientSideBaseVisitor< const typeImport = this.config.useTypeImports ? 'import type' : 'import'; this._additionalImports.push( - `${typeImport} { GraphQLClient, RequestOptions } from 'graphql-request';`, + `${typeImport} { GraphQLClient, type RequestOptions } from 'graphql-request';`, ); if (this.config.rawRequest) { diff --git a/packages/plugins/typescript/graphql-request/tests/__snapshots__/graphql-request.spec.ts.snap b/packages/plugins/typescript/graphql-request/tests/__snapshots__/graphql-request.spec.ts.snap index 6cbd721693..7f81abf9c5 100644 --- a/packages/plugins/typescript/graphql-request/tests/__snapshots__/graphql-request.spec.ts.snap +++ b/packages/plugins/typescript/graphql-request/tests/__snapshots__/graphql-request.spec.ts.snap @@ -8,7 +8,7 @@ export type MakeOptional = Omit & { [SubKey in K]?: export type MakeMaybe = Omit & { [SubKey in K]: Maybe }; export type MakeEmpty = { [_ in K]?: never }; export type Incremental = T | { [P in keyof T]?: P extends ' $fragmentName' | '__typename' ? T[P] : never }; -import { GraphQLClient, RequestOptions } from 'graphql-request'; +import { GraphQLClient, type RequestOptions } from 'graphql-request'; type GraphQLClientRequestHeaders = RequestOptions['requestHeaders']; /** All built-in and custom scalars, mapped to their actual values */ export type Scalars = { @@ -295,7 +295,7 @@ export type MakeOptional = Omit & { [SubKey in K]?: export type MakeMaybe = Omit & { [SubKey in K]: Maybe }; export type MakeEmpty = { [_ in K]?: never }; export type Incremental = T | { [P in keyof T]?: P extends ' $fragmentName' | '__typename' ? T[P] : never }; -import { GraphQLClient, RequestOptions } from 'graphql-request'; +import { GraphQLClient, type RequestOptions } from 'graphql-request'; type GraphQLClientRequestHeaders = RequestOptions['requestHeaders']; import gql from 'graphql-tag'; /** All built-in and custom scalars, mapped to their actual values */ @@ -576,7 +576,7 @@ export type MakeOptional = Omit & { [SubKey in K]?: export type MakeMaybe = Omit & { [SubKey in K]: Maybe }; export type MakeEmpty = { [_ in K]?: never }; export type Incremental = T | { [P in keyof T]?: P extends ' $fragmentName' | '__typename' ? T[P] : never }; -import { GraphQLClient, RequestOptions } from 'graphql-request'; +import { GraphQLClient, type RequestOptions } from 'graphql-request'; type GraphQLClientRequestHeaders = RequestOptions['requestHeaders']; /** All built-in and custom scalars, mapped to their actual values */ export type Scalars = { @@ -856,7 +856,7 @@ export type MakeOptional = Omit & { [SubKey in K]?: export type MakeMaybe = Omit & { [SubKey in K]: Maybe }; export type MakeEmpty = { [_ in K]?: never }; export type Incremental = T | { [P in keyof T]?: P extends ' $fragmentName' | '__typename' ? T[P] : never }; -import type { GraphQLClient, RequestOptions } from 'graphql-request'; +import type { GraphQLClient, type RequestOptions } from 'graphql-request'; import { GraphQLError, print } from 'graphql' type GraphQLClientRequestHeaders = RequestOptions['requestHeaders']; import gql from 'graphql-tag'; @@ -1142,7 +1142,7 @@ export type MakeOptional = Omit & { [SubKey in K]?: export type MakeMaybe = Omit & { [SubKey in K]: Maybe }; export type MakeEmpty = { [_ in K]?: never }; export type Incremental = T | { [P in keyof T]?: P extends ' $fragmentName' | '__typename' ? T[P] : never }; -import { GraphQLClient, RequestOptions } from 'graphql-request'; +import { GraphQLClient, type RequestOptions } from 'graphql-request'; import { GraphQLError } from 'graphql' type GraphQLClientRequestHeaders = RequestOptions['requestHeaders']; /** All built-in and custom scalars, mapped to their actual values */ @@ -1424,7 +1424,7 @@ export type MakeOptional = Omit & { [SubKey in K]?: export type MakeMaybe = Omit & { [SubKey in K]: Maybe }; export type MakeEmpty = { [_ in K]?: never }; export type Incremental = T | { [P in keyof T]?: P extends ' $fragmentName' | '__typename' ? T[P] : never }; -import { GraphQLClient, RequestOptions } from 'graphql-request'; +import { GraphQLClient, type RequestOptions } from 'graphql-request'; type GraphQLClientRequestHeaders = RequestOptions['requestHeaders']; import gql from 'graphql-tag'; /** All built-in and custom scalars, mapped to their actual values */ @@ -1706,7 +1706,7 @@ export type MakeOptional = Omit & { [SubKey in K]?: export type MakeMaybe = Omit & { [SubKey in K]: Maybe }; export type MakeEmpty = { [_ in K]?: never }; export type Incremental = T | { [P in keyof T]?: P extends ' $fragmentName' | '__typename' ? T[P] : never }; -import { GraphQLClient, RequestOptions } from 'graphql-request'; +import { GraphQLClient, type RequestOptions } from 'graphql-request'; import { GraphQLError, print } from 'graphql' type GraphQLClientRequestHeaders = RequestOptions['requestHeaders']; import gql from 'graphql-tag'; @@ -1992,7 +1992,7 @@ export type MakeOptional = Omit & { [SubKey in K]?: export type MakeMaybe = Omit & { [SubKey in K]: Maybe }; export type MakeEmpty = { [_ in K]?: never }; export type Incremental = T | { [P in keyof T]?: P extends ' $fragmentName' | '__typename' ? T[P] : never }; -import { GraphQLClient, RequestOptions } from 'graphql-request'; +import { GraphQLClient, type RequestOptions } from 'graphql-request'; import { GraphQLError, print } from 'graphql' type GraphQLClientRequestHeaders = RequestOptions['requestHeaders']; import gql from 'graphql-tag'; @@ -2278,7 +2278,7 @@ export type MakeOptional = Omit & { [SubKey in K]?: export type MakeMaybe = Omit & { [SubKey in K]: Maybe }; export type MakeEmpty = { [_ in K]?: never }; export type Incremental = T | { [P in keyof T]?: P extends ' $fragmentName' | '__typename' ? T[P] : never }; -import type { GraphQLClient, RequestOptions } from 'graphql-request'; +import type { GraphQLClient, type RequestOptions } from 'graphql-request'; type GraphQLClientRequestHeaders = RequestOptions['requestHeaders']; import gql from 'graphql-tag'; /** All built-in and custom scalars, mapped to their actual values */ @@ -2560,7 +2560,7 @@ export type MakeOptional = Omit & { [SubKey in K]?: export type MakeMaybe = Omit & { [SubKey in K]: Maybe }; export type MakeEmpty = { [_ in K]?: never }; export type Incremental = T | { [P in keyof T]?: P extends ' $fragmentName' | '__typename' ? T[P] : never }; -import { GraphQLClient, RequestOptions } from 'graphql-request'; +import { GraphQLClient, type RequestOptions } from 'graphql-request'; type GraphQLClientRequestHeaders = RequestOptions['requestHeaders']; import gql from 'graphql-tag'; /** All built-in and custom scalars, mapped to their actual values */ diff --git a/packages/plugins/typescript/graphql-request/tests/__snapshots__/graphql-request.v16+.spec.ts.snap b/packages/plugins/typescript/graphql-request/tests/__snapshots__/graphql-request.v16+.spec.ts.snap index b5d134cc88..af64101486 100644 --- a/packages/plugins/typescript/graphql-request/tests/__snapshots__/graphql-request.v16+.spec.ts.snap +++ b/packages/plugins/typescript/graphql-request/tests/__snapshots__/graphql-request.v16+.spec.ts.snap @@ -33,7 +33,7 @@ export function getSdk(client: GraphQLClient, withWrapper: SdkFunctionWrapper = } export type Sdk = ReturnType;", "prepend": [ - "import { GraphQLClient, RequestOptions } from 'graphql-request';", + "import { GraphQLClient, type RequestOptions } from 'graphql-request';", "type GraphQLClientRequestHeaders = RequestOptions['requestHeaders'];", "import gql from 'graphql-tag';", ],