(
data: InfiniteData<unknown>,
param: unknown,
previous?: boolean,
)
| 39 | |
| 40 | // Create function to fetch a page |
| 41 | const fetchPage = async ( |
| 42 | data: InfiniteData<unknown>, |
| 43 | param: unknown, |
| 44 | previous?: boolean, |
| 45 | ): Promise<InfiniteData<unknown>> => { |
| 46 | if (cancelled) { |
| 47 | return Promise.reject(context.signal.reason) |
| 48 | } |
| 49 | |
| 50 | if (param == null && data.pages.length) { |
| 51 | return Promise.resolve(data) |
| 52 | } |
| 53 | |
| 54 | const createQueryFnContext = () => { |
| 55 | const queryFnContext: OmitKeyof< |
| 56 | QueryFunctionContext<QueryKey, unknown>, |
| 57 | 'signal' |
| 58 | > = { |
| 59 | client: context.client, |
| 60 | queryKey: context.queryKey, |
| 61 | pageParam: param, |
| 62 | direction: previous ? 'backward' : 'forward', |
| 63 | meta: context.options.meta, |
| 64 | } |
| 65 | addSignalProperty(queryFnContext) |
| 66 | return queryFnContext as QueryFunctionContext<QueryKey, unknown> |
| 67 | } |
| 68 | |
| 69 | const queryFnContext = createQueryFnContext() |
| 70 | |
| 71 | const page = await queryFn(queryFnContext) |
| 72 | |
| 73 | const { maxPages } = context.options |
| 74 | const addTo = previous ? addToStart : addToEnd |
| 75 | |
| 76 | return { |
| 77 | pages: addTo(data.pages, page, maxPages), |
| 78 | pageParams: addTo(data.pageParams, param, maxPages), |
| 79 | } |
| 80 | } |
| 81 | |
| 82 | // fetch next / previous page? |
| 83 | if (direction && oldPages.length) { |
no test coverage detected