Closed FelixMalfait closed 5 days ago
Disclaimer: This comment was automatically generated with AI. It can give some useful hints as to where to look for, but sometimes it can also give very inaccurate answers so takes this with a pinch of salt :).
To improve pagination on the REST API to match the GraphQL API, follow these steps:
Locate REST API Pagination Logic: Identify where the current pagination logic is implemented in the REST API. This is likely in the controller or service layer handling the REST endpoints.
Update Pagination Response Structure: Modify the response structure to include pageInfo
with hasNextPage
, hasPreviousPage
, startCursor
, and endCursor
.
Example Code:
// Assuming a typical Express.js setup
const getPaginatedData = async (req, res) => {
const { page, limit } = req.query;
const data = await fetchDataFromDatabase(page, limit);
const pageInfo = {
hasNextPage: data.hasNextPage,
hasPreviousPage: data.hasPreviousPage,
startCursor: data.startCursor,
endCursor: data.endCursor
};
res.json({ data: data.items, pageInfo });
};
Update Fetch Logic: Ensure the database query logic supports fetching cursors and determining if there are next/previous pages.
File References:
src/controllers/
.src/services/
for data fetching logic.Implement these changes to align the REST API pagination with the GraphQL API.
Done!
On the GraphQL API, when fetching many records we have:
It would be handy to pass that to the REST API.