OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

Apollo client cursor based using only first and last

  • Thread starter Thread starter yaminoyuki
  • Start date Start date
Y

yaminoyuki

Guest
I am using Apollo client (with react) to get result (graphQl + relay ), and server-side pagination

I have read that using cursor-based pagination is the most reliable way, so previously I was using offset, and now I want to move to the cursor based pagination

in fact, I cannot depend on the cursor itself (using after) since sometimes I need to jump directly to the latest page, so I managed that depending on: after = null, and used first = total edges and used last to get only the needed data

Code:
    const handlePagination = () => {
    const last = Math.min(pagination.pageSize, totalEdges - (pagination.pageIndex * pagination.pageSize));
    refetch({
      after: null,
      first: (pagination.pageIndex + 1) * (pagination.pageSize),
      last: last || pagination.pageSize,
      nameContains: searchInputRef.current,
    });
  };

so here there is no real dependence on the cursor itself, so my question:

1- Is that considered to be cursor-based, or am I re-doing the offset within cursor variables.

2- Is it better to use cursors (after and before) and only in the case of the last page I should use the first and last variables?

<p>I am using Apollo client (with react) to get result (graphQl + relay ), and server-side pagination</p>
<p>I have read that using cursor-based pagination is the most reliable way, so previously I was using offset, and now I want to move to the cursor based pagination</p>
<p>in fact, I cannot depend on the cursor itself (using after) since sometimes I need to jump directly to the latest page, so I managed that depending on:
after = null, and used first = total edges and used last to get only the needed data</p>
<pre><code> const handlePagination = () => {
const last = Math.min(pagination.pageSize, totalEdges - (pagination.pageIndex * pagination.pageSize));
refetch({
after: null,
first: (pagination.pageIndex + 1) * (pagination.pageSize),
last: last || pagination.pageSize,
nameContains: searchInputRef.current,
});
};
</code></pre>
<p>so here there is no real dependence on the cursor itself, so my question:</p>
<p>1- Is that considered to be cursor-based, or am I re-doing the offset within cursor variables.</p>
<p>2- Is it better to use cursors (after and before) and only in the case of the last page I should use the first and last variables?</p>
 

Latest posts

M
Replies
0
Views
1
Meliodas Dragon
M
Top