Using GraphQL with Next.js to fetch data

In this chapter, we will learn how to use basic GraphQL with the Relay framework. But first, let's briefly talk about why GraphQL was introduced and what issues it solves.

When dealing with REST APIs, it is quite common to make some subsequent requests, for example, to get some entities and then for those entities get more sub-entities. By definition, REST endpoints should only provide one type of entity, and any thing else should be fetched from other endpoints, either by following HATEOAS links or by manually creating sub-requests. This increases the amount of network traffic, which forces all clients to re-implement logic for which sub-entities should be fetched and how, and badly affects the 

Get Next.js Quick Start Guide now with the O’Reilly learning platform.

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