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