From 1c2c1350572b0f11f4df2fa1b386461f85c7e26d Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Fri, 21 Nov 2025 14:37:58 +0000 Subject: [PATCH] Refactor: Make query params reactive with accessor functions Co-authored-by: stijn.vanhulle --- .../src/components/Query.tsx | 59 ++++++++++++----- .../src/components/QueryOptions.tsx | 64 ++++++++++++++----- .../__snapshots__/clientDataReturnTypeFull.ts | 27 ++++---- .../__snapshots__/clientGetImportPath.ts | 27 ++++---- .../generators/__snapshots__/findByTags.ts | 27 ++++---- .../__snapshots__/findByTagsObject.ts | 23 +++---- .../findByTagsPathParamsObject.ts | 27 ++++---- .../findByTagsWithCustomQueryKey.ts | 27 ++++---- .../__snapshots__/findByTagsWithZod.ts | 27 ++++---- .../generators/__snapshots__/postAsQuery.ts | 29 +++++---- 10 files changed, 202 insertions(+), 135 deletions(-) diff --git a/packages/plugin-solid-query/src/components/Query.tsx b/packages/plugin-solid-query/src/components/Query.tsx index b3582e8634..b07d9c402a 100644 --- a/packages/plugin-solid-query/src/components/Query.tsx +++ b/packages/plugin-solid-query/src/components/Query.tsx @@ -36,39 +36,47 @@ function getParams({ paramsType, paramsCasing, pathParamsType, dataReturnType, t const TError = `ResponseErrorConfig<${typeSchemas.errors?.map((item) => item.name).join(' | ') || 'Error'}>` if (paramsType === 'object') { + // Wrap pathParams in accessor functions for Solid reactivity + const pathParamsChildren = typeSchemas.pathParams + ? Object.fromEntries( + Object.entries(getPathParams(typeSchemas.pathParams, { typed: true, casing: paramsCasing })) + .map(([key, value]) => [key, value ? { ...value, type: `() => ${value.type}` } : value]) + ) + : {} + return FunctionParams.factory({ data: { mode: 'object', children: { - ...getPathParams(typeSchemas.pathParams, { typed: true, casing: paramsCasing }), + ...pathParamsChildren, data: typeSchemas.request?.name ? { - type: typeSchemas.request?.name, + type: `() => ${typeSchemas.request?.name}`, optional: isOptional(typeSchemas.request?.schema), } : undefined, params: typeSchemas.queryParams?.name ? { - type: typeSchemas.queryParams?.name, + type: `() => ${typeSchemas.queryParams?.name}`, optional: isOptional(typeSchemas.queryParams?.schema), } : undefined, headers: typeSchemas.headerParams?.name ? { - type: typeSchemas.headerParams?.name, + type: `() => ${typeSchemas.headerParams?.name}`, optional: isOptional(typeSchemas.headerParams?.schema), } : undefined, }, }, options: { - type: ` + type: `() => { query?: Partial> & { client?: QueryClient }, client?: ${typeSchemas.request?.name ? `Partial> & { client?: typeof fetch }` : 'Partial & { client?: typeof fetch }'} } `, - default: '{}', + default: '() => ({})', }, }) } @@ -83,30 +91,30 @@ function getParams({ paramsType, paramsCasing, pathParamsType, dataReturnType, t : undefined, data: typeSchemas.request?.name ? { - type: typeSchemas.request?.name, + type: `() => ${typeSchemas.request?.name}`, optional: isOptional(typeSchemas.request?.schema), } : undefined, params: typeSchemas.queryParams?.name ? { - type: typeSchemas.queryParams?.name, + type: `() => ${typeSchemas.queryParams?.name}`, optional: isOptional(typeSchemas.queryParams?.schema), } : undefined, headers: typeSchemas.headerParams?.name ? { - type: typeSchemas.headerParams?.name, + type: `() => ${typeSchemas.headerParams?.name}`, optional: isOptional(typeSchemas.headerParams?.schema), } : undefined, options: { - type: ` + type: `() => { query?: Partial> & { client?: QueryClient }, client?: ${typeSchemas.request?.name ? `Partial> & { client?: typeof fetch }` : 'Partial & { client?: typeof fetch }'} } `, - default: '{}', + default: '() => ({})', }, }) } @@ -147,7 +155,28 @@ export function Query({ typeSchemas, }) - const queryOptions = `${queryOptionsName}(${queryOptionsParams.toCall()}) as unknown as UseBaseQueryOptions` + // Build the unwrapped parameter calls using transformName to call accessor functions + const unwrappedQueryKeyCall = queryKeyParams.toCall({ + transformName(name) { + const param = params.flatParams[name] + if (param && param.type?.startsWith('() =>')) { + return `${name}?.()` + } + return name + }, + }) + + const unwrappedQueryOptionsCall = queryOptionsParams.toCall({ + transformName(name) { + const param = params.flatParams[name] + if (param && param.type?.startsWith('() =>')) { + return `${name}?.()` + } + return name + }, + }) + + const queryOptions = `${queryOptionsName}(${unwrappedQueryOptionsCall}) as unknown as UseBaseQueryOptions` return ( @@ -160,10 +189,10 @@ export function Query({ comments: getComments(operation), }} > - {` - const { query: queryConfig = {}, client: config = {} } = options ?? {} + {` + const { query: queryConfig = {}, client: config = {} } = options?.() ?? {} const { client: queryClient, ...queryOptions } = queryConfig - const queryKey = queryOptions?.queryKey ?? ${queryKeyName}(${queryKeyParams.toCall()}) + const queryKey = queryOptions?.queryKey ?? ${queryKeyName}(${unwrappedQueryKeyCall}) const query = useQuery(() => ({ ...${queryOptions}, diff --git a/packages/plugin-solid-query/src/components/QueryOptions.tsx b/packages/plugin-solid-query/src/components/QueryOptions.tsx index 3c186f21f6..6ee96f9125 100644 --- a/packages/plugin-solid-query/src/components/QueryOptions.tsx +++ b/packages/plugin-solid-query/src/components/QueryOptions.tsx @@ -27,26 +27,34 @@ type GetParamsProps = { function getParams({ paramsType, paramsCasing, pathParamsType, typeSchemas }: GetParamsProps) { if (paramsType === 'object') { + // Wrap pathParams in accessor functions for Solid reactivity + const pathParamsChildren = typeSchemas.pathParams + ? Object.fromEntries( + Object.entries(getPathParams(typeSchemas.pathParams, { typed: true, casing: paramsCasing })) + .map(([key, value]) => [key, value ? { ...value, type: `() => ${value.type}` } : value]) + ) + : {} + return FunctionParams.factory({ data: { mode: 'object', children: { - ...getPathParams(typeSchemas.pathParams, { typed: true, casing: paramsCasing }), + ...pathParamsChildren, data: typeSchemas.request?.name ? { - type: typeSchemas.request?.name, + type: `() => ${typeSchemas.request?.name}`, optional: isOptional(typeSchemas.request?.schema), } : undefined, params: typeSchemas.queryParams?.name ? { - type: typeSchemas.queryParams?.name, + type: `() => ${typeSchemas.queryParams?.name}`, optional: isOptional(typeSchemas.queryParams?.schema), } : undefined, headers: typeSchemas.headerParams?.name ? { - type: typeSchemas.headerParams?.name, + type: `() => ${typeSchemas.headerParams?.name}`, optional: isOptional(typeSchemas.headerParams?.schema), } : undefined, @@ -54,9 +62,9 @@ function getParams({ paramsType, paramsCasing, pathParamsType, typeSchemas }: Ge }, config: { type: typeSchemas.request?.name - ? `Partial> & { client?: typeof fetch }` - : 'Partial & { client?: typeof fetch }', - default: '{}', + ? `() => Partial> & { client?: typeof fetch }` + : '() => Partial & { client?: typeof fetch }', + default: '() => ({})', }, }) } @@ -71,27 +79,27 @@ function getParams({ paramsType, paramsCasing, pathParamsType, typeSchemas }: Ge : undefined, data: typeSchemas.request?.name ? { - type: typeSchemas.request?.name, + type: `() => ${typeSchemas.request?.name}`, optional: isOptional(typeSchemas.request?.schema), } : undefined, params: typeSchemas.queryParams?.name ? { - type: typeSchemas.queryParams?.name, + type: `() => ${typeSchemas.queryParams?.name}`, optional: isOptional(typeSchemas.queryParams?.schema), } : undefined, headers: typeSchemas.headerParams?.name ? { - type: typeSchemas.headerParams?.name, + type: `() => ${typeSchemas.headerParams?.name}`, optional: isOptional(typeSchemas.headerParams?.schema), } : undefined, config: { type: typeSchemas.request?.name - ? `Partial> & { client?: typeof fetch }` - : 'Partial & { client?: typeof fetch }', - default: '{}', + ? `() => Partial> & { client?: typeof fetch }` + : '() => Partial & { client?: typeof fetch }', + default: '() => ({})', }, }) } @@ -114,8 +122,29 @@ export function QueryOptions({ name, clientName, typeSchemas, paramsCasing, para typeSchemas, }) + // Build the unwrapped parameter calls using transformName to call accessor functions + const unwrappedQueryKeyCall = queryKeyParams.toCall({ + transformName(name) { + const param = params.flatParams[name] + if (param && param.type?.startsWith('() =>')) { + return `${name}?.()` + } + return name + }, + }) + + const unwrappedClientCall = clientParams.toCall({ + transformName(name) { + const param = params.flatParams[name] + if (param && param.type?.startsWith('() =>')) { + return `${name}?.()` + } + return name + }, + }) + const enabled = Object.entries(queryKeyParams.flatParams) - .map(([key, item]) => (item && !item.optional ? key : undefined)) + .map(([key, item]) => (item && !item.optional ? `${key}?.()` : undefined)) .filter(Boolean) .join('&& ') @@ -125,13 +154,14 @@ export function QueryOptions({ name, clientName, typeSchemas, paramsCasing, para {` - const queryKey = ${queryKeyName}(${queryKeyParams.toCall()}) + const queryKey = ${queryKeyName}(${unwrappedQueryKeyCall}) return queryOptions<${TData}, ${TError}, ${TData}, typeof queryKey>({ ${enabledText} queryKey, queryFn: async ({ signal }) => { - config.signal = signal - return ${clientName}(${clientParams.toCall()}) + const unwrappedConfig = config?.() ?? {} + unwrappedConfig.signal = signal + return ${clientName}(${unwrappedClientCall}) }, }) `} diff --git a/packages/plugin-solid-query/src/generators/__snapshots__/clientDataReturnTypeFull.ts b/packages/plugin-solid-query/src/generators/__snapshots__/clientDataReturnTypeFull.ts index 72dc6678dc..5616f33d55 100644 --- a/packages/plugin-solid-query/src/generators/__snapshots__/clientDataReturnTypeFull.ts +++ b/packages/plugin-solid-query/src/generators/__snapshots__/clientDataReturnTypeFull.ts @@ -34,11 +34,11 @@ export async function findPetsByTags( } export function findPetsByTagsQueryOptions( - headers: FindPetsByTagsHeaderParams, - params?: FindPetsByTagsQueryParams, - config: Partial & { client?: typeof fetch } = {}, + headers: () => FindPetsByTagsHeaderParams, + params?: () => FindPetsByTagsQueryParams, + config: () => Partial & { client?: typeof fetch } = () => ({}), ) { - const queryKey = findPetsByTagsQueryKey(params) + const queryKey = findPetsByTagsQueryKey(params?.()) return queryOptions< ResponseConfig, ResponseErrorConfig, @@ -47,8 +47,9 @@ export function findPetsByTagsQueryOptions( >({ queryKey, queryFn: async ({ signal }) => { - config.signal = signal - return findPetsByTags(headers, params, config) + const unwrappedConfig = config?.() ?? {} + unwrappedConfig.signal = signal + return findPetsByTags(headers?.(), params?.(), config?.()) }, }) } @@ -63,22 +64,22 @@ export function createFindPetsByTags< TQueryData = ResponseConfig, TQueryKey extends QueryKey = FindPetsByTagsQueryKey, >( - headers: FindPetsByTagsHeaderParams, - params?: FindPetsByTagsQueryParams, - options: { + headers: () => FindPetsByTagsHeaderParams, + params?: () => FindPetsByTagsQueryParams, + options: () => { query?: Partial, ResponseErrorConfig, TData, TQueryData, TQueryKey>> & { client?: QueryClient } client?: Partial & { client?: typeof fetch } - } = {}, + } = () => ({}), ) { - const { query: queryConfig = {}, client: config = {} } = options ?? {} + const { query: queryConfig = {}, client: config = {} } = options?.() ?? {} const { client: queryClient, ...queryOptions } = queryConfig - const queryKey = queryOptions?.queryKey ?? findPetsByTagsQueryKey(params) + const queryKey = queryOptions?.queryKey ?? findPetsByTagsQueryKey(params?.()) const query = useQuery( () => ({ - ...(findPetsByTagsQueryOptions(headers, params, config) as unknown as UseBaseQueryOptions), + ...(findPetsByTagsQueryOptions(headers?.(), params?.(), config) as unknown as UseBaseQueryOptions), queryKey, initialData: null, ...(queryOptions as unknown as Omit), diff --git a/packages/plugin-solid-query/src/generators/__snapshots__/clientGetImportPath.ts b/packages/plugin-solid-query/src/generators/__snapshots__/clientGetImportPath.ts index 2be455a1a3..e57319c3f6 100644 --- a/packages/plugin-solid-query/src/generators/__snapshots__/clientGetImportPath.ts +++ b/packages/plugin-solid-query/src/generators/__snapshots__/clientGetImportPath.ts @@ -34,16 +34,17 @@ export async function findPetsByTags( } export function findPetsByTagsQueryOptions( - headers: FindPetsByTagsHeaderParams, - params?: FindPetsByTagsQueryParams, - config: Partial & { client?: typeof fetch } = {}, + headers: () => FindPetsByTagsHeaderParams, + params?: () => FindPetsByTagsQueryParams, + config: () => Partial & { client?: typeof fetch } = () => ({}), ) { - const queryKey = findPetsByTagsQueryKey(params) + const queryKey = findPetsByTagsQueryKey(params?.()) return queryOptions, FindPetsByTagsQueryResponse, typeof queryKey>({ queryKey, queryFn: async ({ signal }) => { - config.signal = signal - return findPetsByTags(headers, params, config) + const unwrappedConfig = config?.() ?? {} + unwrappedConfig.signal = signal + return findPetsByTags(headers?.(), params?.(), config?.()) }, }) } @@ -58,22 +59,22 @@ export function createFindPetsByTags< TQueryData = FindPetsByTagsQueryResponse, TQueryKey extends QueryKey = FindPetsByTagsQueryKey, >( - headers: FindPetsByTagsHeaderParams, - params?: FindPetsByTagsQueryParams, - options: { + headers: () => FindPetsByTagsHeaderParams, + params?: () => FindPetsByTagsQueryParams, + options: () => { query?: Partial, TData, TQueryData, TQueryKey>> & { client?: QueryClient } client?: Partial & { client?: typeof fetch } - } = {}, + } = () => ({}), ) { - const { query: queryConfig = {}, client: config = {} } = options ?? {} + const { query: queryConfig = {}, client: config = {} } = options?.() ?? {} const { client: queryClient, ...queryOptions } = queryConfig - const queryKey = queryOptions?.queryKey ?? findPetsByTagsQueryKey(params) + const queryKey = queryOptions?.queryKey ?? findPetsByTagsQueryKey(params?.()) const query = useQuery( () => ({ - ...(findPetsByTagsQueryOptions(headers, params, config) as unknown as UseBaseQueryOptions), + ...(findPetsByTagsQueryOptions(headers?.(), params?.(), config) as unknown as UseBaseQueryOptions), queryKey, initialData: null, ...(queryOptions as unknown as Omit), diff --git a/packages/plugin-solid-query/src/generators/__snapshots__/findByTags.ts b/packages/plugin-solid-query/src/generators/__snapshots__/findByTags.ts index 0202ed1a54..e4eb54fdb5 100644 --- a/packages/plugin-solid-query/src/generators/__snapshots__/findByTags.ts +++ b/packages/plugin-solid-query/src/generators/__snapshots__/findByTags.ts @@ -34,16 +34,17 @@ export async function findPetsByTags( } export function findPetsByTagsQueryOptions( - headers: FindPetsByTagsHeaderParams, - params?: FindPetsByTagsQueryParams, - config: Partial & { client?: typeof fetch } = {}, + headers: () => FindPetsByTagsHeaderParams, + params?: () => FindPetsByTagsQueryParams, + config: () => Partial & { client?: typeof fetch } = () => ({}), ) { - const queryKey = findPetsByTagsQueryKey(params) + const queryKey = findPetsByTagsQueryKey(params?.()) return queryOptions, FindPetsByTagsQueryResponse, typeof queryKey>({ queryKey, queryFn: async ({ signal }) => { - config.signal = signal - return findPetsByTags(headers, params, config) + const unwrappedConfig = config?.() ?? {} + unwrappedConfig.signal = signal + return findPetsByTags(headers?.(), params?.(), config?.()) }, }) } @@ -58,22 +59,22 @@ export function createFindPetsByTags< TQueryData = FindPetsByTagsQueryResponse, TQueryKey extends QueryKey = FindPetsByTagsQueryKey, >( - headers: FindPetsByTagsHeaderParams, - params?: FindPetsByTagsQueryParams, - options: { + headers: () => FindPetsByTagsHeaderParams, + params?: () => FindPetsByTagsQueryParams, + options: () => { query?: Partial, TData, TQueryData, TQueryKey>> & { client?: QueryClient } client?: Partial & { client?: typeof fetch } - } = {}, + } = () => ({}), ) { - const { query: queryConfig = {}, client: config = {} } = options ?? {} + const { query: queryConfig = {}, client: config = {} } = options?.() ?? {} const { client: queryClient, ...queryOptions } = queryConfig - const queryKey = queryOptions?.queryKey ?? findPetsByTagsQueryKey(params) + const queryKey = queryOptions?.queryKey ?? findPetsByTagsQueryKey(params?.()) const query = useQuery( () => ({ - ...(findPetsByTagsQueryOptions(headers, params, config) as unknown as UseBaseQueryOptions), + ...(findPetsByTagsQueryOptions(headers?.(), params?.(), config) as unknown as UseBaseQueryOptions), queryKey, initialData: null, ...(queryOptions as unknown as Omit), diff --git a/packages/plugin-solid-query/src/generators/__snapshots__/findByTagsObject.ts b/packages/plugin-solid-query/src/generators/__snapshots__/findByTagsObject.ts index 73f21eec10..099408fa74 100644 --- a/packages/plugin-solid-query/src/generators/__snapshots__/findByTagsObject.ts +++ b/packages/plugin-solid-query/src/generators/__snapshots__/findByTagsObject.ts @@ -33,15 +33,16 @@ export async function findPetsByTags( } export function findPetsByTagsQueryOptions( - { headers, params }: { headers: FindPetsByTagsHeaderParams; params?: FindPetsByTagsQueryParams }, - config: Partial & { client?: typeof fetch } = {}, + { headers, params }: { headers: () => FindPetsByTagsHeaderParams; params?: () => FindPetsByTagsQueryParams }, + config: () => Partial & { client?: typeof fetch } = () => ({}), ) { - const queryKey = findPetsByTagsQueryKey(params) + const queryKey = findPetsByTagsQueryKey(params?.()) return queryOptions, FindPetsByTagsQueryResponse, typeof queryKey>({ queryKey, queryFn: async ({ signal }) => { - config.signal = signal - return findPetsByTags({ headers, params }, config) + const unwrappedConfig = config?.() ?? {} + unwrappedConfig.signal = signal + return findPetsByTags({ headers: headers?.(), params: params?.() }, config?.()) }, }) } @@ -56,21 +57,21 @@ export function createFindPetsByTags< TQueryData = FindPetsByTagsQueryResponse, TQueryKey extends QueryKey = FindPetsByTagsQueryKey, >( - { headers, params }: { headers: FindPetsByTagsHeaderParams; params?: FindPetsByTagsQueryParams }, - options: { + { headers, params }: { headers: () => FindPetsByTagsHeaderParams; params?: () => FindPetsByTagsQueryParams }, + options: () => { query?: Partial, TData, TQueryData, TQueryKey>> & { client?: QueryClient } client?: Partial & { client?: typeof fetch } - } = {}, + } = () => ({}), ) { - const { query: queryConfig = {}, client: config = {} } = options ?? {} + const { query: queryConfig = {}, client: config = {} } = options?.() ?? {} const { client: queryClient, ...queryOptions } = queryConfig - const queryKey = queryOptions?.queryKey ?? findPetsByTagsQueryKey(params) + const queryKey = queryOptions?.queryKey ?? findPetsByTagsQueryKey(params?.()) const query = useQuery( () => ({ - ...(findPetsByTagsQueryOptions({ headers, params }, config) as unknown as UseBaseQueryOptions), + ...(findPetsByTagsQueryOptions({ headers: headers?.(), params: params?.() }, config) as unknown as UseBaseQueryOptions), queryKey, initialData: null, ...(queryOptions as unknown as Omit), diff --git a/packages/plugin-solid-query/src/generators/__snapshots__/findByTagsPathParamsObject.ts b/packages/plugin-solid-query/src/generators/__snapshots__/findByTagsPathParamsObject.ts index 0202ed1a54..e4eb54fdb5 100644 --- a/packages/plugin-solid-query/src/generators/__snapshots__/findByTagsPathParamsObject.ts +++ b/packages/plugin-solid-query/src/generators/__snapshots__/findByTagsPathParamsObject.ts @@ -34,16 +34,17 @@ export async function findPetsByTags( } export function findPetsByTagsQueryOptions( - headers: FindPetsByTagsHeaderParams, - params?: FindPetsByTagsQueryParams, - config: Partial & { client?: typeof fetch } = {}, + headers: () => FindPetsByTagsHeaderParams, + params?: () => FindPetsByTagsQueryParams, + config: () => Partial & { client?: typeof fetch } = () => ({}), ) { - const queryKey = findPetsByTagsQueryKey(params) + const queryKey = findPetsByTagsQueryKey(params?.()) return queryOptions, FindPetsByTagsQueryResponse, typeof queryKey>({ queryKey, queryFn: async ({ signal }) => { - config.signal = signal - return findPetsByTags(headers, params, config) + const unwrappedConfig = config?.() ?? {} + unwrappedConfig.signal = signal + return findPetsByTags(headers?.(), params?.(), config?.()) }, }) } @@ -58,22 +59,22 @@ export function createFindPetsByTags< TQueryData = FindPetsByTagsQueryResponse, TQueryKey extends QueryKey = FindPetsByTagsQueryKey, >( - headers: FindPetsByTagsHeaderParams, - params?: FindPetsByTagsQueryParams, - options: { + headers: () => FindPetsByTagsHeaderParams, + params?: () => FindPetsByTagsQueryParams, + options: () => { query?: Partial, TData, TQueryData, TQueryKey>> & { client?: QueryClient } client?: Partial & { client?: typeof fetch } - } = {}, + } = () => ({}), ) { - const { query: queryConfig = {}, client: config = {} } = options ?? {} + const { query: queryConfig = {}, client: config = {} } = options?.() ?? {} const { client: queryClient, ...queryOptions } = queryConfig - const queryKey = queryOptions?.queryKey ?? findPetsByTagsQueryKey(params) + const queryKey = queryOptions?.queryKey ?? findPetsByTagsQueryKey(params?.()) const query = useQuery( () => ({ - ...(findPetsByTagsQueryOptions(headers, params, config) as unknown as UseBaseQueryOptions), + ...(findPetsByTagsQueryOptions(headers?.(), params?.(), config) as unknown as UseBaseQueryOptions), queryKey, initialData: null, ...(queryOptions as unknown as Omit), diff --git a/packages/plugin-solid-query/src/generators/__snapshots__/findByTagsWithCustomQueryKey.ts b/packages/plugin-solid-query/src/generators/__snapshots__/findByTagsWithCustomQueryKey.ts index 08bd8417de..1076904306 100644 --- a/packages/plugin-solid-query/src/generators/__snapshots__/findByTagsWithCustomQueryKey.ts +++ b/packages/plugin-solid-query/src/generators/__snapshots__/findByTagsWithCustomQueryKey.ts @@ -34,16 +34,17 @@ export async function findPetsByTags( } export function findPetsByTagsQueryOptions( - headers: FindPetsByTagsHeaderParams, - params?: FindPetsByTagsQueryParams, - config: Partial & { client?: typeof fetch } = {}, + headers: () => FindPetsByTagsHeaderParams, + params?: () => FindPetsByTagsQueryParams, + config: () => Partial & { client?: typeof fetch } = () => ({}), ) { - const queryKey = findPetsByTagsQueryKey(params) + const queryKey = findPetsByTagsQueryKey(params?.()) return queryOptions, FindPetsByTagsQueryResponse, typeof queryKey>({ queryKey, queryFn: async ({ signal }) => { - config.signal = signal - return findPetsByTags(headers, params, config) + const unwrappedConfig = config?.() ?? {} + unwrappedConfig.signal = signal + return findPetsByTags(headers?.(), params?.(), config?.()) }, }) } @@ -58,22 +59,22 @@ export function createFindPetsByTags< TQueryData = FindPetsByTagsQueryResponse, TQueryKey extends QueryKey = FindPetsByTagsQueryKey, >( - headers: FindPetsByTagsHeaderParams, - params?: FindPetsByTagsQueryParams, - options: { + headers: () => FindPetsByTagsHeaderParams, + params?: () => FindPetsByTagsQueryParams, + options: () => { query?: Partial, TData, TQueryData, TQueryKey>> & { client?: QueryClient } client?: Partial & { client?: typeof fetch } - } = {}, + } = () => ({}), ) { - const { query: queryConfig = {}, client: config = {} } = options ?? {} + const { query: queryConfig = {}, client: config = {} } = options?.() ?? {} const { client: queryClient, ...queryOptions } = queryConfig - const queryKey = queryOptions?.queryKey ?? findPetsByTagsQueryKey(params) + const queryKey = queryOptions?.queryKey ?? findPetsByTagsQueryKey(params?.()) const query = useQuery( () => ({ - ...(findPetsByTagsQueryOptions(headers, params, config) as unknown as UseBaseQueryOptions), + ...(findPetsByTagsQueryOptions(headers?.(), params?.(), config) as unknown as UseBaseQueryOptions), queryKey, initialData: null, ...(queryOptions as unknown as Omit), diff --git a/packages/plugin-solid-query/src/generators/__snapshots__/findByTagsWithZod.ts b/packages/plugin-solid-query/src/generators/__snapshots__/findByTagsWithZod.ts index 0202ed1a54..e4eb54fdb5 100644 --- a/packages/plugin-solid-query/src/generators/__snapshots__/findByTagsWithZod.ts +++ b/packages/plugin-solid-query/src/generators/__snapshots__/findByTagsWithZod.ts @@ -34,16 +34,17 @@ export async function findPetsByTags( } export function findPetsByTagsQueryOptions( - headers: FindPetsByTagsHeaderParams, - params?: FindPetsByTagsQueryParams, - config: Partial & { client?: typeof fetch } = {}, + headers: () => FindPetsByTagsHeaderParams, + params?: () => FindPetsByTagsQueryParams, + config: () => Partial & { client?: typeof fetch } = () => ({}), ) { - const queryKey = findPetsByTagsQueryKey(params) + const queryKey = findPetsByTagsQueryKey(params?.()) return queryOptions, FindPetsByTagsQueryResponse, typeof queryKey>({ queryKey, queryFn: async ({ signal }) => { - config.signal = signal - return findPetsByTags(headers, params, config) + const unwrappedConfig = config?.() ?? {} + unwrappedConfig.signal = signal + return findPetsByTags(headers?.(), params?.(), config?.()) }, }) } @@ -58,22 +59,22 @@ export function createFindPetsByTags< TQueryData = FindPetsByTagsQueryResponse, TQueryKey extends QueryKey = FindPetsByTagsQueryKey, >( - headers: FindPetsByTagsHeaderParams, - params?: FindPetsByTagsQueryParams, - options: { + headers: () => FindPetsByTagsHeaderParams, + params?: () => FindPetsByTagsQueryParams, + options: () => { query?: Partial, TData, TQueryData, TQueryKey>> & { client?: QueryClient } client?: Partial & { client?: typeof fetch } - } = {}, + } = () => ({}), ) { - const { query: queryConfig = {}, client: config = {} } = options ?? {} + const { query: queryConfig = {}, client: config = {} } = options?.() ?? {} const { client: queryClient, ...queryOptions } = queryConfig - const queryKey = queryOptions?.queryKey ?? findPetsByTagsQueryKey(params) + const queryKey = queryOptions?.queryKey ?? findPetsByTagsQueryKey(params?.()) const query = useQuery( () => ({ - ...(findPetsByTagsQueryOptions(headers, params, config) as unknown as UseBaseQueryOptions), + ...(findPetsByTagsQueryOptions(headers?.(), params?.(), config) as unknown as UseBaseQueryOptions), queryKey, initialData: null, ...(queryOptions as unknown as Omit), diff --git a/packages/plugin-solid-query/src/generators/__snapshots__/postAsQuery.ts b/packages/plugin-solid-query/src/generators/__snapshots__/postAsQuery.ts index 06b57ed48d..329da12c32 100644 --- a/packages/plugin-solid-query/src/generators/__snapshots__/postAsQuery.ts +++ b/packages/plugin-solid-query/src/generators/__snapshots__/postAsQuery.ts @@ -41,17 +41,18 @@ export async function updatePetWithForm( export function updatePetWithFormQueryOptions( petId: UpdatePetWithFormPathParams['petId'], - data?: UpdatePetWithFormMutationRequest, - params?: UpdatePetWithFormQueryParams, - config: Partial> & { client?: typeof fetch } = {}, + data?: () => UpdatePetWithFormMutationRequest, + params?: () => UpdatePetWithFormQueryParams, + config: () => Partial> & { client?: typeof fetch } = () => ({}), ) { - const queryKey = updatePetWithFormQueryKey(petId, data, params) + const queryKey = updatePetWithFormQueryKey(petId, data?.(), params?.()) return queryOptions, UpdatePetWithFormMutationResponse, typeof queryKey>({ - enabled: !!petId, + enabled: !!petId?.(), queryKey, queryFn: async ({ signal }) => { - config.signal = signal - return updatePetWithForm(petId, data, params, config) + const unwrappedConfig = config?.() ?? {} + unwrappedConfig.signal = signal + return updatePetWithForm(petId, data?.(), params?.(), config?.()) }, }) } @@ -66,22 +67,22 @@ export function createUpdatePetWithForm< TQueryKey extends QueryKey = UpdatePetWithFormQueryKey, >( petId: UpdatePetWithFormPathParams['petId'], - data?: UpdatePetWithFormMutationRequest, - params?: UpdatePetWithFormQueryParams, - options: { + data?: () => UpdatePetWithFormMutationRequest, + params?: () => UpdatePetWithFormQueryParams, + options: () => { query?: Partial, TData, TQueryData, TQueryKey>> & { client?: QueryClient } client?: Partial> & { client?: typeof fetch } - } = {}, + } = () => ({}), ) { - const { query: queryConfig = {}, client: config = {} } = options ?? {} + const { query: queryConfig = {}, client: config = {} } = options?.() ?? {} const { client: queryClient, ...queryOptions } = queryConfig - const queryKey = queryOptions?.queryKey ?? updatePetWithFormQueryKey(petId, data, params) + const queryKey = queryOptions?.queryKey ?? updatePetWithFormQueryKey(petId, data?.(), params?.()) const query = useQuery( () => ({ - ...(updatePetWithFormQueryOptions(petId, data, params, config) as unknown as UseBaseQueryOptions), + ...(updatePetWithFormQueryOptions(petId, data?.(), params?.(), config) as unknown as UseBaseQueryOptions), queryKey, initialData: null, ...(queryOptions as unknown as Omit),