(
Observer: typeof QueryObserver,
options: MaybeRefOrGetter<
UseQueryOptionsGeneric<
TQueryFnData,
TError,
TData,
TQueryData,
TQueryKey,
TPageParam
>
>,
queryClient?: QueryClient,
)
| 110 | * @returns The query result as `ref`s, plus the `suspense` function. |
| 111 | */ |
| 112 | export function useBaseQuery< |
| 113 | TQueryFnData, |
| 114 | TError, |
| 115 | TData, |
| 116 | TQueryData, |
| 117 | TQueryKey extends QueryKey, |
| 118 | TPageParam, |
| 119 | >( |
| 120 | Observer: typeof QueryObserver, |
| 121 | options: MaybeRefOrGetter< |
| 122 | UseQueryOptionsGeneric< |
| 123 | TQueryFnData, |
| 124 | TError, |
| 125 | TData, |
| 126 | TQueryData, |
| 127 | TQueryKey, |
| 128 | TPageParam |
| 129 | > |
| 130 | >, |
| 131 | queryClient?: QueryClient, |
| 132 | ): UseBaseQueryReturnType<TData, TError> { |
| 133 | if (process.env.NODE_ENV === 'development') { |
| 134 | if (!getCurrentScope()) { |
| 135 | console.warn( |
| 136 | 'vue-query composable like "useQuery()" should only be used inside a "setup()" function or a running effect scope. They might otherwise lead to memory leaks.', |
| 137 | ) |
| 138 | } |
| 139 | } |
| 140 | |
| 141 | const client = queryClient || useQueryClient() |
| 142 | |
| 143 | const defaultedOptions = computed(() => { |
| 144 | let resolvedOptions = options |
| 145 | if (typeof resolvedOptions === 'function') { |
| 146 | resolvedOptions = resolvedOptions() |
| 147 | } |
| 148 | const clonedOptions = cloneDeepUnref(resolvedOptions as any) |
| 149 | |
| 150 | // A zero-arg function is a Vue getter and must run here so its refs are tracked. |
| 151 | // `(query) => boolean` is query-core's callback and is left for core to call. |
| 152 | if ( |
| 153 | typeof clonedOptions.enabled === 'function' && |
| 154 | clonedOptions.enabled.length === 0 |
| 155 | ) { |
| 156 | clonedOptions.enabled = clonedOptions.enabled() |
| 157 | } |
| 158 | |
| 159 | const defaulted: DefaultedQueryObserverOptions< |
| 160 | TQueryFnData, |
| 161 | TError, |
| 162 | TData, |
| 163 | TQueryData, |
| 164 | TQueryKey |
| 165 | > = client.defaultQueryOptions(clonedOptions) |
| 166 | |
| 167 | defaulted._optimisticResults = client.isRestoring?.value |
| 168 | ? 'isRestoring' |
| 169 | : 'optimistic' |
no test coverage detected