( defaultOptions: any, useRQHook: (options: any, queryClient?: any) => any, overrideOptions?: Partial<UseInfiniteQueryOptions> )
| 16 | } |
| 17 | |
| 18 | export const createBaseQuery = ( |
| 19 | defaultOptions: any, |
| 20 | useRQHook: (options: any, queryClient?: any) => any, |
| 21 | overrideOptions?: Partial<UseInfiniteQueryOptions> |
| 22 | ): any => { |
| 23 | if (process.env.NODE_ENV !== 'production') { |
| 24 | // @ts-ignore |
| 25 | if (defaultOptions.useDefaultOptions) { |
| 26 | console.error( |
| 27 | '[Bug] useDefaultOptions is not supported, please use middleware instead.' |
| 28 | ) |
| 29 | } |
| 30 | |
| 31 | // @ts-ignore |
| 32 | if (defaultOptions.queryFn) { |
| 33 | console.error( |
| 34 | '[Bug] queryFn is not supported, please use fetcher instead.' |
| 35 | ) |
| 36 | } |
| 37 | } |
| 38 | |
| 39 | const getQueryOptions = (fetcherFn: any, variables: any) => { |
| 40 | return { |
| 41 | queryFn: |
| 42 | variables && variables === ReactQuery.skipToken |
| 43 | ? ReactQuery.skipToken |
| 44 | : (context: QueryFunctionContext) => fetcherFn(variables, context), |
| 45 | queryKey: getFullKey(defaultOptions.queryKey, variables), |
| 46 | } |
| 47 | } |
| 48 | |
| 49 | const getKey = (variables?: any) => |
| 50 | getFullKey(defaultOptions.queryKey, variables) |
| 51 | |
| 52 | const getOptions = (variables: any) => { |
| 53 | return { |
| 54 | ...defaultOptions, |
| 55 | ...getQueryOptions(defaultOptions.fetcher, variables), |
| 56 | } |
| 57 | } |
| 58 | |
| 59 | const getFetchOptions = (variables: any) => { |
| 60 | return { |
| 61 | ...getQueryOptions(defaultOptions.fetcher, variables), |
| 62 | queryKeyHashFn: defaultOptions.queryKeyHashFn, |
| 63 | getPreviousPageParam: defaultOptions.getPreviousPageParam, |
| 64 | getNextPageParam: defaultOptions.getNextPageParam, |
| 65 | initialPageParam: defaultOptions.initialPageParam, |
| 66 | staleTime: defaultOptions.staleTime, |
| 67 | gcTime: defaultOptions.gcTime, |
| 68 | } |
| 69 | } |
| 70 | |
| 71 | const useBaseHook = ( |
| 72 | options: QueryBaseHookOptions, |
| 73 | queryClient?: QueryClient |
| 74 | ) => { |
| 75 | return useRQHook( |
no test coverage detected
searching dependent graphs…