(
options: {
queryFn?: QueryFunction<TQueryFnData, TQueryKey> | SkipToken
queryHash?: string
},
fetchOptions?: FetchOptions<TQueryFnData>,
)
| 444 | export type SkipToken = typeof skipToken |
| 445 | |
| 446 | export function ensureQueryFn< |
| 447 | TQueryFnData = unknown, |
| 448 | TQueryKey extends QueryKey = QueryKey, |
| 449 | >( |
| 450 | options: { |
| 451 | queryFn?: QueryFunction<TQueryFnData, TQueryKey> | SkipToken |
| 452 | queryHash?: string |
| 453 | }, |
| 454 | fetchOptions?: FetchOptions<TQueryFnData>, |
| 455 | ): QueryFunction<TQueryFnData, TQueryKey> { |
| 456 | if (process.env.NODE_ENV !== 'production') { |
| 457 | if (options.queryFn === skipToken) { |
| 458 | console.error( |
| 459 | `Attempted to invoke queryFn when set to skipToken. This is likely a configuration error. Query hash: '${options.queryHash}'`, |
| 460 | ) |
| 461 | } |
| 462 | } |
| 463 | |
| 464 | // if we attempt to retry a fetch that was triggered from an initialPromise |
| 465 | // when we don't have a queryFn yet, we can't retry, so we just return the already rejected initialPromise |
| 466 | // if an observer has already mounted, we will be able to retry with that queryFn |
| 467 | if (!options.queryFn && fetchOptions?.initialPromise) { |
| 468 | return () => fetchOptions.initialPromise! |
| 469 | } |
| 470 | |
| 471 | if (!options.queryFn || options.queryFn === skipToken) { |
| 472 | return () => |
| 473 | Promise.reject(new Error(`Missing queryFn: '${options.queryHash}'`)) |
| 474 | } |
| 475 | |
| 476 | return options.queryFn |
| 477 | } |
| 478 | |
| 479 | export function shouldThrowError<T extends (...args: Array<any>) => boolean>( |
| 480 | throwOnError: boolean | T | undefined, |
no outgoing calls
no test coverage detected