Skip to content

Commit a175ace

Browse files
committed
Pass options to useQuery and useMutation
1 parent be863c5 commit a175ace

File tree

2 files changed

+26
-12
lines changed

2 files changed

+26
-12
lines changed

src/lib/seam/use-seam-mutation.ts

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,18 @@ import {
1111

1212
import { NullSeamClientError, useSeamClient } from 'lib/seam/use-seam-client.js'
1313

14-
type MutationOptions = Omit<UseMutationOptions, 'mutationFn'>
15-
1614
export function useSeamMutation<T extends SeamHttpEndpointMutationPaths>(
1715
endpointPath: T,
1816
options?: Parameters<SeamHttpEndpoints[T]>[1],
19-
_mutationOptions: MutationOptions = {}
20-
): UseMutationResult<
21-
Awaited<ReturnType<SeamHttpEndpoints[T]>>,
22-
SeamHttpApiError,
23-
Parameters<SeamHttpEndpoints[T]>[1]
24-
> {
17+
mutationOptions: MutationOptions<
18+
MutationData<T>,
19+
SeamHttpApiError,
20+
MutationParameters<T>
21+
> = {}
22+
): UseMutationResult<MutationData<T>, SeamHttpApiError, MutationParameters<T>> {
2523
const { endpointClient: client } = useSeamClient()
2624
return useMutation({
25+
...mutationOptions,
2726
mutationFn: async (parameters) => {
2827
if (client === null) throw new NullSeamClientError()
2928
// Using @ts-expect-error over any is preferred, but not possible here because TypeScript will run out of memory.
@@ -33,3 +32,13 @@ export function useSeamMutation<T extends SeamHttpEndpointMutationPaths>(
3332
},
3433
})
3534
}
35+
36+
type MutationData<T extends SeamHttpEndpointMutationPaths> = Awaited<
37+
ReturnType<SeamHttpEndpoints[T]>
38+
>
39+
40+
type MutationParameters<T extends SeamHttpEndpointMutationPaths> = Parameters<
41+
SeamHttpEndpoints[T]
42+
>[1]
43+
44+
type MutationOptions<X, Y, Z> = Omit<UseMutationOptions<X, Y, Z>, 'mutationFn'>

src/lib/seam/use-seam-query.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,16 @@ import {
1111

1212
import { useSeamClient } from 'lib/seam/use-seam-client.js'
1313

14-
type QueryOptions = Omit<UseQueryOptions, 'queryKey' | 'queryFn'>
15-
1614
export function useSeamQuery<T extends SeamHttpEndpointQueryPaths>(
1715
endpointPath: T,
1816
parameters?: Parameters<SeamHttpEndpoints[T]>[0],
1917
options?: Parameters<SeamHttpEndpoints[T]>[1],
20-
_queryOptions: QueryOptions = {}
21-
): UseQueryResult<Awaited<ReturnType<SeamHttpEndpoints[T]>>, SeamHttpApiError> {
18+
queryOptions: QueryOptions<QueryData<T>, SeamHttpApiError> = {}
19+
): UseQueryResult<QueryData<T>, SeamHttpApiError> {
2220
const { endpointClient: client } = useSeamClient()
2321
return useQuery({
2422
enabled: client != null,
23+
...queryOptions,
2524
queryKey: [endpointPath, parameters],
2625
queryFn: async () => {
2726
if (client == null) return null
@@ -32,3 +31,9 @@ export function useSeamQuery<T extends SeamHttpEndpointQueryPaths>(
3231
},
3332
})
3433
}
34+
35+
type QueryData<T extends SeamHttpEndpointQueryPaths> = Awaited<
36+
ReturnType<SeamHttpEndpoints[T]>
37+
>
38+
39+
type QueryOptions<X, Y> = Omit<UseQueryOptions<X, Y>, 'queryKey' | 'queryFn'>

0 commit comments

Comments
 (0)