Building a full stack e-commerce application with React, Apollo, and GraphQL
In this section, you'll connect the React web application to the GraphQL server. A GraphQL Server on a Next.js API Route is used to create a single GraphQL endpoint that uses dynamic mock data as a source. Apollo Client is used by React to consume this endpoint and handle state management for your application.
Creating a GraphQL server with Next.js
In Chapter 3, Building a Dynamic Project Management Board, we already created a React application with Next.js, in which it was already mentioned that you can also use it to create API endpoints. By looking at the files in our directory for this chapter, you can see that the pages
directory contains a directory called api
with a file called hello.js
. All the directories and files that you create in the pages
directory become available as a route in the browser, but if you create them under the api
directory in pages
, they are called API routes. The hello...