(
{
queries,
...options
}: ShallowOption & {
queries:
| MaybeRefDeep<UseQueriesOptionsArg<T>>
| MaybeRefDeep<
readonly [
...{ [K in keyof T]: GetUseQueryOptionsForUseQueries<T[K]> },
]
>
combine?: (result: UseQueriesResults<T>) => TCombinedResult
},
queryClient?: QueryClient,
)
| 232 | ] |
| 233 | |
| 234 | export function useQueries< |
| 235 | T extends Array<any>, |
| 236 | TCombinedResult = UseQueriesResults<T>, |
| 237 | >( |
| 238 | { |
| 239 | queries, |
| 240 | ...options |
| 241 | }: ShallowOption & { |
| 242 | queries: |
| 243 | | MaybeRefDeep<UseQueriesOptionsArg<T>> |
| 244 | | MaybeRefDeep< |
| 245 | readonly [ |
| 246 | ...{ [K in keyof T]: GetUseQueryOptionsForUseQueries<T[K]> }, |
| 247 | ] |
| 248 | > |
| 249 | combine?: (result: UseQueriesResults<T>) => TCombinedResult |
| 250 | }, |
| 251 | queryClient?: QueryClient, |
| 252 | ): Readonly<Ref<TCombinedResult>> { |
| 253 | if (process.env.NODE_ENV === 'development') { |
| 254 | if (!getCurrentScope()) { |
| 255 | console.warn( |
| 256 | '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.', |
| 257 | ) |
| 258 | } |
| 259 | } |
| 260 | |
| 261 | const client = queryClient || useQueryClient() |
| 262 | |
| 263 | const defaultedQueries = computed(() => { |
| 264 | // Only unref the top level array. |
| 265 | const queriesRaw = unref(queries) as ReadonlyArray<any> |
| 266 | |
| 267 | // Unref the rest for each element in the top level array. |
| 268 | return queriesRaw.map((queryOptions) => { |
| 269 | const clonedOptions = cloneDeepUnref(queryOptions) |
| 270 | |
| 271 | if (typeof clonedOptions.enabled === 'function') { |
| 272 | clonedOptions.enabled = queryOptions.enabled() |
| 273 | } |
| 274 | |
| 275 | const defaulted = client.defaultQueryOptions(clonedOptions) |
| 276 | defaulted._optimisticResults = client.isRestoring?.value |
| 277 | ? 'isRestoring' |
| 278 | : 'optimistic' |
| 279 | |
| 280 | return defaulted |
| 281 | }) |
| 282 | }) |
| 283 | |
| 284 | const observer = new QueriesObserver<TCombinedResult>( |
| 285 | client, |
| 286 | defaultedQueries.value, |
| 287 | options as QueriesObserverOptions<TCombinedResult>, |
| 288 | ) |
| 289 | |
| 290 | const getOptimisticResult = () => { |
| 291 | const [results, getCombinedResult] = observer.getOptimisticResult( |
searching dependent graphs…