Lighouse @paginator with all records

Lighouse @paginator with all records

Problem Description:

I am using @paginator directive on my query and my client wants to get all records of posts from the query. This is my code:

posts: [Post!]! @paginate

I tested this querys:

posts(first:0) {id} #works but don't get all records
posts(first:-1) {id} #error

One way was to get all records was to use the value of total inside the paginatorInfo and make a new query with that value on the first:.

 posts(first:0) {
   paginatorInfo {
     total
   }
 }

For optimization making 2 querys to get all records is very bad.

Solution – 1

The best approach I got was to make a new query (now having two querys for posts with different directives and names) like:

allPosts: [Post!]! @all

Other approaches but not so clean:

  • Set pagination.max_count to null in the config/lighthouse.php and do (first: 100000000) (the int is 32 bits so has a limit).
  • Change the @paginantor to a @field(resolver:) and do pagination with pure php.
Rate this post
We use cookies in order to give you the best possible experience on our website. By continuing to use this site, you agree to our use of cookies.
Accept
Reject