You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I want to implement the following pagination component in my site:
It makes sense to me to provide the data for this component in Payload because I think that links should be treated as content. Users can add redirects, specify canonical URLs, add categories… Handling all of that on the frontend seems inadequate, so I want to handle it on the backend, where all of that is managed.
Finally, I can use that data to render my component on the frontend.
My main concern is that there are two queries in play. First is the actual BlogPosts query, then I additionally have to do await payload.find() in my resolver function to get the total page count of the collection.
It'd be ideal if I could use result.totalPages from the BlogPosts query, rather than making a brand new database lookup with payload.find() and also making sure to keep limit and page the same as in the main posts query. In other words, is it possible to do it like this:
Can I somehow add my custom pagination as a part of the main BlogPosts query and use its arguments, along with the underlying result containing totalPages, to avoid this inefficiency?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
I want to implement the following pagination component in my site:
It makes sense to me to provide the data for this component in Payload because I think that links should be treated as content. Users can add redirects, specify canonical URLs, add categories… Handling all of that on the frontend seems inadequate, so I want to handle it on the backend, where all of that is managed.
I've added a custom GraphQL query as per the Payload GraphQL docs:
Then, I can use that query like so:
…and get the following result:
Finally, I can use that data to render my component on the frontend.
My main concern is that there are two queries in play. First is the actual
BlogPosts
query, then I additionally have to doawait payload.find()
in my resolver function to get the total page count of the collection.It'd be ideal if I could use
result.totalPages
from theBlogPosts
query, rather than making a brand new database lookup withpayload.find()
and also making sure to keeplimit
andpage
the same as in the main posts query. In other words, is it possible to do it like this:Can I somehow add my custom pagination as a part of the main
BlogPosts
query and use its arguments, along with the underlying result containingtotalPages
, to avoid this inefficiency?Beta Was this translation helpful? Give feedback.
All reactions