Relay's connection model

Relay's power becomes obvious when we have to work with a big dataset. When, for example, we have hundreds of inspirational quotes, a common practice to do on listing pages is to paginate them, for example, by showing 20 quotes per page. Relay's connection model will help us implement this pagination feature quickly and efficiently.

We'll first need to convert the allQuotes field into a Relay connection field; we'll rename it quotesConnection to make that clear to clients who want to use it.

Just like any other custom type, we need to define a type for this new quotesConnection field. However, we can use a Relay helper in this case to create the new type. In schema/main.js, right after we define the QuoteType, add this: ...

Get Learning GraphQL and Relay now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.