|
5 | 5 | type InfiniteQueryPageParamsOptions,
|
6 | 6 | type QueryClient,
|
7 | 7 | type QueryFunction,
|
| 8 | + type SkipToken, |
8 | 9 | queryOptions as defineQueryOptions,
|
9 | 10 | skipToken,
|
10 | 11 | useInfiniteQuery,
|
@@ -81,21 +82,22 @@ function createVueQueryProxyDecoration<TRouter extends AnyTRPCRouter>(
|
81 | 82 | { trpcOptions, queryOptions }: { trpcOptions: any; queryOptions: any },
|
82 | 83 | { type = 'query' }: { type?: QueryType } = {},
|
83 | 84 | ) {
|
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) |
87 | 90 |
|
88 |
| - if (input === skipToken) return skipToken |
| 91 | + const output = await trpc.query(joinedPath, input, { |
| 92 | + signal, |
| 93 | + ...trpcOptions, |
| 94 | + }) |
89 | 95 |
|
90 |
| - const output = await trpc.query(joinedPath, input, { |
91 |
| - signal, |
92 |
| - ...trpcOptions, |
93 |
| - }) |
| 96 | + if (type === 'queries') return { output, input } |
94 | 97 |
|
95 |
| - if (type === 'queries') return { output, input } |
96 |
| - |
97 |
| - return output |
98 |
| - }) |
| 98 | + return output |
| 99 | + }, |
| 100 | + ) |
99 | 101 |
|
100 | 102 | return defineQueryOptions({
|
101 | 103 | queryKey: computed(() => getQueryKey(path, toValue(_input), type)),
|
|
0 commit comments