Pagination in React and GraphQL
By pagination, most of the time, we mean the batch querying of data. Currently, we query for all posts, chats, and messages in our database. If you think about how much data Facebook stores inside one chat with your friends, you will realize that it is unrealistic to fetch all of the messages and data ever shared at once. A better solution is to use pagination. With pagination, we always have a page size, or a limit, of how many items we want to fetch per request. We also have a page or offset number, from which we can start to select data rows.
In this section, we're going to look at how to use pagination with the posts feed, as it is the most straightforward example. In Chapter 5, Reusable React Components and React Hooks, we will focus on writing efficient and reusable React code. Sequelize offers the pagination feature by default. We can first insert some more demo posts so that we can paginate in batches of 10.
We need to adjust the backend...