-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(solid-query): separate queryOptions from createQuery (#7806)
Co-authored-by: Dominik Dorfmeister <[email protected]>
- Loading branch information
1 parent
23c3da2
commit 1dcd532
Showing
7 changed files
with
196 additions
and
186 deletions.
There are no files selected for viewing
8 changes: 3 additions & 5 deletions
8
.../__tests__/createInfiniteQuery.test-d.tsx → ...__tests__/infiniteQueryOptions.test-d.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
import type { | ||
DataTag, | ||
DefaultError, | ||
InfiniteData, | ||
QueryKey, | ||
} from '@tanstack/query-core' | ||
import type { FunctionedParams, SolidInfiniteQueryOptions } from './types' | ||
|
||
export type UndefinedInitialDataInfiniteOptions< | ||
TQueryFnData, | ||
TError = DefaultError, | ||
TData = InfiniteData<TQueryFnData>, | ||
TQueryKey extends QueryKey = QueryKey, | ||
TPageParam = unknown, | ||
> = FunctionedParams< | ||
SolidInfiniteQueryOptions< | ||
TQueryFnData, | ||
TError, | ||
TData, | ||
TQueryFnData, | ||
TQueryKey, | ||
TPageParam | ||
> & { | ||
initialData?: undefined | ||
} | ||
> | ||
|
||
type NonUndefinedGuard<T> = T extends undefined ? never : T | ||
|
||
export type DefinedInitialDataInfiniteOptions< | ||
TQueryFnData, | ||
TError = DefaultError, | ||
// should we handle page param correctly | ||
TData = InfiniteData<TQueryFnData>, | ||
TQueryKey extends QueryKey = QueryKey, | ||
TPageParam = unknown, | ||
> = FunctionedParams< | ||
SolidInfiniteQueryOptions< | ||
TQueryFnData, | ||
TError, | ||
TData, | ||
TQueryFnData, | ||
TQueryKey, | ||
TPageParam | ||
> & { | ||
initialData: | ||
| NonUndefinedGuard<InfiniteData<TQueryFnData, TPageParam>> | ||
| (() => NonUndefinedGuard<InfiniteData<TQueryFnData, TPageParam>>) | ||
} | ||
> | ||
export function infiniteQueryOptions< | ||
TQueryFnData, | ||
TError = DefaultError, | ||
TData = InfiniteData<TQueryFnData>, | ||
TQueryKey extends QueryKey = QueryKey, | ||
TPageParam = unknown, | ||
>( | ||
options: ReturnType< | ||
DefinedInitialDataInfiniteOptions< | ||
TQueryFnData, | ||
TError, | ||
TData, | ||
TQueryKey, | ||
TPageParam | ||
> | ||
>, | ||
): ReturnType< | ||
DefinedInitialDataInfiniteOptions< | ||
TQueryFnData, | ||
TError, | ||
TData, | ||
TQueryKey, | ||
TPageParam | ||
> | ||
> & { | ||
queryKey: DataTag<TQueryKey, InfiniteData<TQueryFnData>> | ||
} | ||
export function infiniteQueryOptions< | ||
TQueryFnData, | ||
TError = DefaultError, | ||
TData = InfiniteData<TQueryFnData>, | ||
TQueryKey extends QueryKey = QueryKey, | ||
TPageParam = unknown, | ||
>( | ||
options: ReturnType< | ||
UndefinedInitialDataInfiniteOptions< | ||
TQueryFnData, | ||
TError, | ||
TData, | ||
TQueryKey, | ||
TPageParam | ||
> | ||
>, | ||
): ReturnType< | ||
UndefinedInitialDataInfiniteOptions< | ||
TQueryFnData, | ||
TError, | ||
TData, | ||
TQueryKey, | ||
TPageParam | ||
> | ||
> & { | ||
queryKey: DataTag<TQueryKey, InfiniteData<TQueryFnData>> | ||
} | ||
|
||
export function infiniteQueryOptions(options: unknown) { | ||
return options | ||
} |
Oops, something went wrong.