From fa84f5d018f2428266bf03c9b0cd34e18f0a06b3 Mon Sep 17 00:00:00 2001 From: Landon Gavin Date: Fri, 3 May 2024 12:37:10 -0400 Subject: [PATCH] fix(prefetch): import QueryClient type In some instances the QueryClient import was not be auto-detected by ts-morph. Explicitly add the type import. --- src/createImports.mts | 5 +++++ tests/__snapshots__/createSource.test.ts.snap | 8 ++++---- tests/__snapshots__/generate.test.ts.snap | 1 + 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/createImports.mts b/src/createImports.mts index 62fa92a..b302ee0 100644 --- a/src/createImports.mts +++ b/src/createImports.mts @@ -43,6 +43,11 @@ export const createImports = ({ false, undefined, ts.factory.createNamedImports([ + ts.factory.createImportSpecifier( + true, + undefined, + ts.factory.createIdentifier("QueryClient") + ), ts.factory.createImportSpecifier( false, undefined, diff --git a/tests/__snapshots__/createSource.test.ts.snap b/tests/__snapshots__/createSource.test.ts.snap index c482300..afea9f7 100644 --- a/tests/__snapshots__/createSource.test.ts.snap +++ b/tests/__snapshots__/createSource.test.ts.snap @@ -11,7 +11,7 @@ export * from "./queries"; exports[`createSource > createSource 2`] = ` "// generated with @7nohe/openapi-react-query-codegen@1.0.0 -import { useQuery, useSuspenseQuery, useMutation, UseQueryResult, UseQueryOptions, UseMutationOptions, UseMutationResult } from "@tanstack/react-query"; +import { type QueryClient, useQuery, useSuspenseQuery, useMutation, UseQueryResult, UseQueryOptions, UseMutationOptions, UseMutationResult } from "@tanstack/react-query"; import { DefaultService } from "../requests/services.gen"; import { Pet, NewPet, Error, $OpenApiTs } from "../requests/types.gen"; export type DefaultServiceFindPetsDefaultResponse = Awaited>; @@ -41,7 +41,7 @@ exports[`createSource > createSource 3`] = ` "// generated with @7nohe/openapi-react-query-codegen@1.0.0 import * as Common from "./common"; -import { useQuery, useSuspenseQuery, useMutation, UseQueryResult, UseQueryOptions, UseMutationOptions, UseMutationResult } from "@tanstack/react-query"; +import { type QueryClient, useQuery, useSuspenseQuery, useMutation, UseQueryResult, UseQueryOptions, UseMutationOptions, UseMutationResult } from "@tanstack/react-query"; import { DefaultService } from "../requests/services.gen"; import { Pet, NewPet, Error, $OpenApiTs } from "../requests/types.gen"; /** @@ -119,7 +119,7 @@ exports[`createSource > createSource 4`] = ` "// generated with @7nohe/openapi-react-query-codegen@1.0.0 import * as Common from "./common"; -import { useQuery, useSuspenseQuery, useMutation, UseQueryResult, UseQueryOptions, UseMutationOptions, UseMutationResult } from "@tanstack/react-query"; +import { type QueryClient, useQuery, useSuspenseQuery, useMutation, UseQueryResult, UseQueryOptions, UseMutationOptions, UseMutationResult } from "@tanstack/react-query"; import { DefaultService } from "../requests/services.gen"; import { Pet, NewPet, Error, $OpenApiTs } from "../requests/types.gen"; /** @@ -164,7 +164,7 @@ exports[`createSource > createSource 5`] = ` "// generated with @7nohe/openapi-react-query-codegen@1.0.0 import * as Common from "./common"; -import { useQuery, useSuspenseQuery, useMutation, UseQueryResult, UseQueryOptions, UseMutationOptions, UseMutationResult } from "@tanstack/react-query"; +import { type QueryClient, useQuery, useSuspenseQuery, useMutation, UseQueryResult, UseQueryOptions, UseMutationOptions, UseMutationResult } from "@tanstack/react-query"; import { DefaultService } from "../requests/services.gen"; import { Pet, NewPet, Error, $OpenApiTs } from "../requests/types.gen"; /** diff --git a/tests/__snapshots__/generate.test.ts.snap b/tests/__snapshots__/generate.test.ts.snap index d08bee3..4ed7d5d 100644 --- a/tests/__snapshots__/generate.test.ts.snap +++ b/tests/__snapshots__/generate.test.ts.snap @@ -39,6 +39,7 @@ export * from "./queries"; exports[`generate > prefetch.ts 1`] = ` "// generated with @7nohe/openapi-react-query-codegen@1.0.0 +import { type QueryClient } from "@tanstack/react-query"; import { DefaultService } from "../requests/services.gen"; import * as Common from "./common"; /**