MCPcopy Create free account
hub / github.com/TanStack/query / fetchPage

Function fetchPage

packages/query-core/src/infiniteQueryBehavior.ts:53–92  ·  view source on GitHub ↗
(
          data: InfiniteData<unknown>,
          param: unknown,
          previous?: boolean,
        )

Source from the content-addressed store, hash-verified

51
52 // Create function to fetch a page
53 const fetchPage = async (
54 data: InfiniteData<unknown>,
55 param: unknown,
56 previous?: boolean,
57 ): Promise<InfiniteData<unknown>> => {
58 if (cancelled) {
59 return Promise.reject(context.signal.reason)
60 }
61
62 if (param == null && data.pages.length) {
63 return Promise.resolve(data)
64 }
65
66 const createQueryFnContext = () => {
67 const queryFnContext: OmitKeyof<
68 QueryFunctionContext<QueryKey, unknown>,
69 'signal'
70 > = {
71 client: context.client,
72 queryKey: context.queryKey,
73 pageParam: param,
74 direction: previous ? 'backward' : 'forward',
75 meta: context.options.meta,
76 }
77 addSignalProperty(queryFnContext)
78 return queryFnContext as QueryFunctionContext<QueryKey, unknown>
79 }
80
81 const queryFnContext = createQueryFnContext()
82
83 const page = await queryFn(queryFnContext)
84
85 const { maxPages } = context.options
86 const addTo = previous ? addToStart : addToEnd
87
88 return {
89 pages: addTo(data.pages, page, maxPages),
90 pageParams: addTo(data.pageParams, param, maxPages),
91 }
92 }
93
94 // fetch next / previous page?
95 if (direction && oldPages.length) {

Callers 1

fetchFnFunction · 0.85

Calls 2

createQueryFnContextFunction · 0.85
queryFnFunction · 0.50

Tested by

no test coverage detected