Hands-On Full-Stack Web Development with GraphQL and React
Build scalable full-stack applications while learning to solve complex problems with GraphQL
Sebastian Grebe
- 468 pages
- English
- ePUB (mobile friendly)
- Available on iOS & Android
Hands-On Full-Stack Web Development with GraphQL and React
Build scalable full-stack applications while learning to solve complex problems with GraphQL
Sebastian Grebe
About This Book
Unearth the power of GraphQL, React, Apollo, Node, and Express to build a scalable, production ready application
Key Features
- Build full stack applications with modern APIs using GraphQL and Apollo
- Integrate Apollo into React and build frontend components using GraphQL
- Implement a self-updating notification pop-up with a unique GraphQL feature called Subscriptions
Book Description
React, one of the most widely used JavaScript frameworks, allows developers to build fast and scalable front end applications for any use case. GraphQL is the modern way of querying an API. It represents an alternative to REST and is the next evolution in web development. Combining these two revolutionary technologies will give you a future-proof and scalable stack you can start building your business around.
This book will guide you in implementing applications by using React, Apollo, Node.js and SQL. We'll focus on solving complex problems with GraphQL, such as abstracting multi-table database architectures and handling image uploads. Our client, and server will be powered by Apollo. Finally we will go ahead and build a complete Graphbook. While building the app, we'll cover the tricky parts of connecting React to the back end, and maintaining and synchronizing state. We'll learn all about querying data and authenticating users. We'll write test cases to verify the front end and back end functionality for our application and cover deployment. By the end of the book, you will be proficient in using GraphQL and React for your full-stack development requirements.
What you will learn
- Resolve data from multi-table database and system architectures
- Build a GraphQL API by implementing models and schemas with Apollo and Sequelize
- Set up an Apollo Client and build front end components using React
- Use Mocha to test your full-stack application
- Write complex React components and share data across them
- Deploy your application using Docker
Who this book is for
The book is for web developers who want to enhance their skills and build complete full stack applications using industry standards. Familiarity with JavaScript, React, and GraphQL is expected to get the most from this book.
Frequently asked questions
Information
Reusable React Components
- React patterns
- Structured React components
- Rendering nested components
- The React Context API
- The Apollo Consumer component
Introducing React patterns
- Controlled components
- Stateless functions
- Conditional rendering
- Rendering children
Controlled components
import React, { Component } from 'react';
import gql from 'graphql-tag';
import { Mutation } from 'react-apollo';
const ADD_POST = gql`
mutation addPost($post : PostInput!) {
addPost(post : $post) {
id
text
user {
username
avatar
}
}
}`;
export default class Feed extends Component {
constructor(props) {
super(props);
this.textArea = React.createRef();
}
render() {
const self = this;
return (
<div className="container">
<div className="postForm">
<Mutation mutation={ADD_POST}>
{addPost => (
<form onSubmit={e => {
e.preventDefault();
addPost({ variables: { post: { text:
self.textArea.current.value } } });
}}>
<textarea ref={this.textArea} placeholder="Write your
custom post!"/>
<input type="submit" value="Submit" />
</form>
)}
</Mutation>
</div>
</div>
)
}
}
Stateless functions
mkdir src/client/components
touch src/client/components/loading.js
import React from 'react';
export default ({color, size}) => {
var style = {
backgroundColor: '#6ca6fd',
width: 40,
height: 40,
};
if(typeof color !== typeof undefined) {
style.color = color;
}
if(typeof size !== typeof undefined) {
style.width = size;
style.height = size;
}
return <div className="bouncer" style={style}></div>
}