Skip to content

Commit d24f44c

Browse files
authored
feat(solid-query): queryOptions helper for solid-query (#5355)
* feat: queryOptions helper for solid-query * add tests * fix imports
1 parent d2c856c commit d24f44c

File tree

3 files changed

+44
-2
lines changed

3 files changed

+44
-2
lines changed

packages/solid-query/src/__tests__/createQuery.types.test.tsx

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { createQuery } from '../index'
1+
import { createQuery, queryOptions } from '../index'
22

33
export type Equal<X, Y> = (<T>() => T extends X ? 1 : 2) extends <
44
T,
@@ -31,6 +31,26 @@ describe('initialData', () => {
3131
})
3232
})
3333

34+
it('TData should be defined when passed through queryOptions', () => {
35+
doNotExecute(() => {
36+
const options = queryOptions(() => ({
37+
queryKey: ['key'],
38+
queryFn: () => {
39+
return {
40+
wow: true,
41+
}
42+
},
43+
initialData: {
44+
wow: true,
45+
},
46+
}))
47+
const { data } = createQuery(options)
48+
49+
const result: Expect<Equal<{ wow: boolean }, typeof data>> = true
50+
return result
51+
})
52+
})
53+
3454
it('TData should always be defined when initialData is provided as a function which ALWAYS returns the data', () => {
3555
doNotExecute(() => {
3656
const { data } = createQuery(() => ({

packages/solid-query/src/createQuery.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,28 @@ type DefinedInitialDataOptions<
3434
}
3535
>
3636

37+
export function queryOptions<
38+
TQueryFnData = unknown,
39+
TError = unknown,
40+
TData = TQueryFnData,
41+
TQueryKey extends QueryKey = QueryKey,
42+
>(
43+
options: UndefinedInitialDataOptions<TQueryFnData, TError, TData, TQueryKey>,
44+
): UndefinedInitialDataOptions<TQueryFnData, TError, TData, TQueryKey>
45+
46+
export function queryOptions<
47+
TQueryFnData = unknown,
48+
TError = unknown,
49+
TData = TQueryFnData,
50+
TQueryKey extends QueryKey = QueryKey,
51+
>(
52+
options: DefinedInitialDataOptions<TQueryFnData, TError, TData, TQueryKey>,
53+
): DefinedInitialDataOptions<TQueryFnData, TError, TData, TQueryKey>
54+
55+
export function queryOptions(options: unknown) {
56+
return options
57+
}
58+
3759
export function createQuery<
3860
TQueryFnData = unknown,
3961
TError = DefaultError,

packages/solid-query/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export type {
1515
QueryClientConfig,
1616
InfiniteQueryObserverOptions,
1717
} from './QueryClient'
18-
export { createQuery } from './createQuery'
18+
export { createQuery, queryOptions } from './createQuery'
1919
export {
2020
QueryClientContext,
2121
QueryClientProvider,

0 commit comments

Comments
 (0)