How to do the simplest pagination in GraphQL? (using Star War API)

How to do the simplest pagination in GraphQL? (using Star War API)


0

I was able to find how to get the first N or last N elements:

{
 allPeople(first: 2) {
   people {
     name
     birthYear
   }
 }
}

However, it is typical that some websites use

www.my-site.com/people?page=3

as a bookmark to see page 3 of the results.

For example, the Star War API has 82 people (actors / actresses), so let’s say if I show 5 persons per page, then I may have a URL

www.my-site.com/people?page=12

and let users send to their friends. The solution I see to do pagination is to use a cursor, so will it work for getting page 12 directly? If it involves getting results 12 times (each time using a cursor to get the next 5 records), then it seems it is not efficient.

Is there a simple way to do it?

P.S. if I remember correctly, if the underlying DB is relational DB, then there is no SQL statements that says: "fetch me records 1000000 to 1000050", because there is no "ordering by number" or "percentage of records" concept such as "give me records of 50% to 52% percentile." However, if there are just small amount of records, like 82 above or 220 total, I think the method is to get all records, and then return either 5 or 10 to the web client, so that instead of sending all 82 records, it is enough to send just 5.


Load 7 more related questions


Show fewer related questions

0



Leave a Reply

Your email address will not be published. Required fields are marked *