apollographql / apollo-client-nextjs

Apollo Client support for the Next.js App Router
https://www.npmjs.com/package/@apollo/experimental-nextjs-app-support
MIT License
352 stars 25 forks source link

Is there a way to handle Pagination using getClient() ? #242

Closed jovanhartono closed 1 month ago

jovanhartono commented 1 month ago

or it must be using useSuspenseQuery()?

the idea is to pass the endCursor to the URL state -> get the cursor params -> passing it into the getClient().query({query: someQuery, variables: {after: cursor}})

phryneas commented 1 month ago

I don't see why it wouldn't work - what problem are you encountering?

jovanhartono commented 1 month ago

I don't see why it wouldn't work - what problem are you encountering?

the cached value not merged with the new data

jovanhartono commented 1 month ago

i have this query

Screenshot 2024-03-18 at 16 44 54 Screenshot 2024-03-18 at 16 45 35 Screenshot 2024-03-18 at 16 46 06

when show more button is clicked, it will append the searchParams after=endCursor, the page Component will then get the searchParams and pass it into the variables. i have tried this but the previous values are cleared. any idea why?

phryneas commented 1 month ago

the cached value not merged with the new data

Yes, that's to be expected. You are in React Server Components.

React Server Components only exist for a single render conceptually - there is no "persistence", they are 100% stateless.

You can have a RSC render page 8 and then go to page 9 and render that in isolation, but you can never render page 9 and have page 8 "merged into it" because it doesn't have any knowledge that you were on page 8 before.

=> You can do "pagination" as in "show a single page at a time", but not "infinite scrolling".

jovanhartono commented 1 month ago

the cached value not merged with the new data

Yes, that's to be expected. You are in React Server Components.

React Server Components only exist for a single render conceptually - there is no "persistence", they are 100% stateless.

You can have a RSC render page 8 and then go to page 9 and render that in isolation, but you can never render page 9 and have page 8 "merged into it" because it doesn't have any knowledge that you were on page 8 before.

=> You can do "pagination" as in "show a single page at a time", but not "infinite scrolling".

thank you for your time. your responses helped me a lot. closing this issue

github-actions[bot] commented 1 month ago

Do you have any feedback for the maintainers? Please tell us by taking a one-minute survey. Your responses will help us understand Apollo Client usage and allow us to serve you better.