I have a table where I load the 1st 100 records and want to be able to load the subsequent records in batches of 100. The following setup goes in an infinite loop (hence the inserted break) and keeps adding the first 100. I must not be passing the variables for first and after but am at a loss?
Here's the process so far:
After the first query "getJobberQuotesAwaitingResponse1stSet"
It triggers a JS query to update the table:
const initialData = getJobberQuotesAwaitingResponse1stSet.data.records || [];
table4DataSource.setValue(initialData);
Upon success it triggers another JS query "fetchRemainingData" which is where I'm having trouble passing the correct variables to get the next 100 until there are no more records (pages).
async function fetchRemainingData() {
let allRecords = table4DataSource.value || [];
let hasNextPage = getJobberQuotesAwaitingResponse1stSet.data.pageInfo.hasNextPage;
let afterCursor = getJobberQuotesAwaitingResponse1stSet.data.pageInfo.endCursor;
while (hasNextPage) {
const data = await getJobberQuotesAwaitingResponseRemainder.trigger({
additionalScope: {
first: 100,
after: afterCursor
}
});
if (data && data.pageInfo) {
const newRecords = data.records || [];
allRecords = [...allRecords, ...newRecords];
hasNextPage = data.pageInfo.hasNextPage;
afterCursor = data.pageInfo.endCursor;
table4DataSource.setValue(allRecords);
break;
// Exit if no more pages
if (!hasNextPage) break;
} else {
// Exit if the response structure is not as expected
console.log("No more pages or invalid response structure.");
break;
}
}
}
return fetchRemainingData();
My query getJobberQuotesAwaitingResponseRemainder:
query getJobberQuotesAwaitingResponse($first: Int = 100, $after: String) {
quotes(filter: {status: awaiting_response}, first: $first, after: $after) {
edges {
node {
id
quoteNumber
clientHubViewedAt
quoteStatus
jobberWebUri
transitionedAt
client {
companyName
defaultEmails
}
property {
address {
street
city
}
}
}
}
totalCount
pageInfo {
endCursor
hasNextPage
hasPreviousPage
startCursor
}
}
}