Pagination

Another important feature for Hackernews is pagination.

Fetching all links that were ever posted to the app would soon become too much, besides not being that useful. Instead, we show just a few links at a time, letting the user navigate to pages with older links.

In this tutorial, you’ll implement a simple pagination approach that’s called limit-offset pagination. This method would not work with Relay on the frontend since Relay requires cursor-based pagination using the concept of connections. You can read more about pagination in the GraphQL docs.

To make this work you want to have a schema like that:

type Query {
  allLinks(filter: LinkFilter, skip: Int, first: Int): [Link!]!
}

All done!

Add skip and first to LinksSearch

In https://github.com/howtographql/graphql-ruby you can find the final project + a couple of further improvements 😺.

Next Chapter

Summary

You learned how to build a GraphQL server with graphql-ruby & Ruby and best practices for filters, authentication, pagination and subscriptions.

Go to next chapter