Skip to content

Commit 6e1ed8b

Browse files
committed
fix: set skipToken as queryFn, not as return value
1 parent 9f520b1 commit 6e1ed8b

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

src/index.ts

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
type InfiniteQueryPageParamsOptions,
66
type QueryClient,
77
type QueryFunction,
8+
type SkipToken,
89
queryOptions as defineQueryOptions,
910
skipToken,
1011
useInfiniteQuery,
@@ -81,21 +82,22 @@ function createVueQueryProxyDecoration<TRouter extends AnyTRPCRouter>(
8182
{ trpcOptions, queryOptions }: { trpcOptions: any; queryOptions: any },
8283
{ type = 'query' }: { type?: QueryType } = {},
8384
) {
84-
// eslint-disable-next-line unicorn/consistent-function-scoping
85-
const queryFn = computed<QueryFunction>(() => async ({ signal }) => {
86-
const input = toValue(_input)
85+
const queryFn = computed<QueryFunction | SkipToken>(() =>
86+
toValue(_input) === skipToken
87+
? skipToken
88+
: async ({ signal }) => {
89+
const input = toValue(_input)
8790

88-
if (input === skipToken) return skipToken
91+
const output = await trpc.query(joinedPath, input, {
92+
signal,
93+
...trpcOptions,
94+
})
8995

90-
const output = await trpc.query(joinedPath, input, {
91-
signal,
92-
...trpcOptions,
93-
})
96+
if (type === 'queries') return { output, input }
9497

95-
if (type === 'queries') return { output, input }
96-
97-
return output
98-
})
98+
return output
99+
},
100+
)
99101

100102
return defineQueryOptions({
101103
queryKey: computed(() => getQueryKey(path, toValue(_input), type)),

0 commit comments

Comments
 (0)