Closed webel closed 1 year ago
@webel the response from ZDK has cursor-based pagination baked in, so you can fetch additional pages by incrementing with the cursor. There's a fairly robust working example up at https://github.com/ourzora/nouns-marketplace/blob/main/%40filter/hooks/useTokensQuery.ts, for reference. It uses the useSWRInfinite hook to manage refreshing, which is super flexible.
Pertinent bits:
async function getNFTs(query: TokensQueryArgs): Promise<GetNFTReturnType> {
const resp = await zdk.tokens(query)
const tokens = resp.tokens.nodes
/* @ts-ignore */
.map((token) => transformNFTZDK(token, { rawData: token }))
.map(prepareJson)
return {
tokens,
nextCursor: resp.tokens.pageInfo.endCursor, // <-- PASS THIS INTO PAGINATION
}
}
and then note how the cursor is passed in as the after value:
pagination: {
after: previousPageData?.nextCursor,
limit: PAGE_SIZE,
},
Hm, that looks like the top-level pagination for the nft endpoint, I was wondering more if I could get the next cursor for one of the nested returns (events). I guess I might just have to call events endpoint directly?
Ah, yes, missed that. Sorry. Yes, targeting events separately would be the way to go here.
In the graphql playground I can see that I can add pagination input for events when querying the token endpoint, how would I accomplish this with the zdk? At the moment I only receive 10 events back, and I was hoping to either be able to paginate them or just set a somewhat high limit.