Book Image

Full-Stack Web Development with GraphQL and React - Second Edition

By : Sebastian Grebe
Book Image

Full-Stack Web Development with GraphQL and React - Second Edition

By: Sebastian Grebe

Overview of this book

React and GraphQL, when combined, provide you with a very dynamic, efficient, and stable tech stack to build web-based applications. GraphQL is a modern solution for querying an API that represents an alternative to REST and is the next evolution in web development. This book guides you in creating a full-stack web application from scratch using modern web technologies such as Apollo, Express.js, Node.js, and React. First, you’ll start by configuring and setting up your development environment. Next, the book demonstrates how to solve complex problems with GraphQL, such as abstracting multi-table database architectures and handling image uploads using Sequelize. You’ll then build a complete Graphbook from scratch. While doing so, you’ll cover the tricky parts of connecting React to the backend, and maintaining and synchronizing state. In addition to this, you’ll also learn how to write Reusable React components and use React Hooks. Later chapters will guide you through querying data and authenticating users in order to enable user privacy. Finally, you’ll explore how to deploy your application on AWS and ensure continuous deployment using Docker and CircleCI. By the end of this web development book, you'll have learned how to build and deploy scalable full-stack applications with ease using React and GraphQL.
Table of Contents (17 chapters)
1
Section 1: Building the Stack
5
Section 2: Building the Application
14
Section 3: Preparing for Deployment

What this book covers

Chapter 1, Preparing Your Development Environment, explains the architecture of an application by going through some core concepts, the complete process, and preparing a working React setup. We will see how React, Apollo Client, and Express.js fit together and cover some good practices when working with React. Further, we will show you how to debug the frontend with React Developer Tools.

Chapter 2, Setting Up GraphQL with Express.js, teaches you how to configure your backend by installing Express.js and Apollo via NPM. Express.js will be used for the web server, which handles and passes all GraphQL requests to Apollo.

Chapter 3, Connecting to the Database, discusses the opportunities that GraphQL offers when it comes to mutating and querying data. As an example, we will use traditional SQL to build a full application. To simplify the database code, we will use Sequelize, which lets us query our SQL Server with a normal JavaScript object and also allows us to use MySQL, MSSQL, PostgresSQL, or just a SQLite file. We will build models and schemas for users and posts in Apollo and Sequelize.

Chapter 4, Hooking Apollo into React, is where you will learn how to hook Apollo into React and build frontend components to send GraphQL requests. This chapter will explain Apollo-specific configurations.

Chapter 5, Reusable React Components and React Hooks, with the basic concepts and flow of fetching and presenting data clear, will dive deeper into writing more complex React components and sharing data across them.

Chapter 6, Authentication with Apollo and React, will explain the common ways of authenticating a user on the web and in GraphQL. You will be guided through building a complete authentication workflow by using best practices.

Chapter 7, Handling Image Uploads, is the point by which you will have a working authentication and authorization system built on top of Apollo. Moving on, to go beyond normal requests with JSON responses as with GraphQL, we will now upload images via Apollo and save them in separate object storage such as AWS S3.

Chapter 8, Routing in React, is where, to build a complete application for the end user, you will implement some further features, such as a profile page. We will accomplish this by installing React Router v5.

Chapter 9, Implementing Server-Side Rendering, covers server-side rendering. For many applications, this is a must-have. It is important for SEO but can also have positive effects on your end user. This chapter will focus on getting your current application moved to a server-side rendered setup.

Chapter 10, Real-Time Subscriptions, looks at how our application is a great use case for WebSocket and Apollo subscriptions. Many of the applications we use daily have a self-updating notification bar. This chapter will focus on how to build this feature with a more or less experimental GraphQL and Apollo feature called subscriptions.

Chapter 11, Writing Tests for React and Node.js, looks at how a real production-ready application always has an automated testing environment. We will use Mocha, a JavaScript unit testing framework, and Enzyme, a React testing tool, to ensure the quality of our application. This chapter will focus on testing the GraphQL backend and how to properly test React applications with Enzyme.

Chapter 12, Continuous Deployment with CircleCI and AWS, studies deployment. Deploying an application means no more uploading files manually via FTP. Nowadays, you can virtually run your application in the cloud without having a complete server running. For easy deployment of our application, we will use Docker. Before deploying our application, we will quickly cover a basic continuous deployment setup, which will let you deploy all your new code with ease. This chapter will explain how to deploy your applications using Git, Docker, AWS, and CircleCI.