Skip to content

Docker + Hot Loading + Node + Express + PostgreSQL + Knex + GraphQL + React + Redux + React Router

License

Notifications You must be signed in to change notification settings

beauvankirk/graphql-react-starter

 
 

Repository files navigation

GraphQL React Starter

GraphQL Node.js Starter is a hot-reloading boilerplate using Node.js, JavaScript through Babel and using GraphQL for API creations and consumption. For client-side, this uses React, React-Router and Redux. For the database portion, this uses PostgreSQL and a query-builder Knex.js

The purpose of this starter kit is to be as close to being a real-world starter while keeping it simple and flexible.

Current Status: still in development, but feel free to fork and contribute.

Installation

# Installs dependencies and sets up the development database. This uses `yarn` 
# if you have it but defaults to `npm` if you don't
make install

Development

# In development mode, everything is streamed from the source code. No files are 
# created (except the in-memory compilation of webpack-middleware). This allows 
# hot reloading to happen.

# start both api and client process
make start

# Uses PM2 for watch, management, monitoring. The meta data is inside this 
# directory's .pm2. You must prepend that in order to access pm2 commands.
PM2_HOME='.pm2' ./node_modules/.bin/pm2 list

# alternatively, you can use:
npm run pm2 [list|help|..]

Production

# Compiles and minifies both api and client into ./dist
make build

# Next, compress and copy the entire ./dist to a proper server. You do not need 
# to copy anything else from the repository.

# Run the client. `http-server` is just an example server. Use Nginx, Apache or 
# whatever you like to run the client. Everything you need is compiled in .dist.
NODE_ENV=production CLIENT_PORT=3000 API_PORT=8080 http-server ./dist

# Run the API. You must use `node` here. All ES2015+ syntax have been compiled. 
# If you are getting unexpected token errors, upgrade your node binaries. Note 
# that this is expecting a PostgreSQL server. You can change the options in the 
# `knexfile.js` and use a different database if you want.
NODE_ENV=production API_PORT=8080 node ./api/index.js

Docker

make do-up

Roadmap and Status

  • Hot Reloading
  • React
  • Redux
  • Webpack 2
  • React Router
  • ESLint
  • .editorconfig
  • GraphQL integration with Express
  • Modularize Schema and Resolvers
  • Database Schema with relationships (1-1/1-M/M-M)
  • Separate API Server and Client server
  • Production vs Development build
  • GraphQL client integration: Apollo
  • GraphQL + Redux
  • GraphQL query example
  • GraphQL mutation example
  • Convert scripts to Makefile
  • Process Management
  • Dockerize Each Layer
  • docker-compose up

Schema-First Design Steps

This centers your application development around your feature requirements, skewed a bit towards UI. Having the graphql abstraction allows you to focus on features rather than modeling your data and queries based on a rigid database schema.

Define Schema

Describe the graphql schema centered around your front-end requirements. This is not the same as Database Design, though in many cases, the schema could be a direct representation of your table relationships.

Define Resolvers

Define the resolvers, to match entities from your schema

Create Mocks

Mocking APIs are typically time consuming and often becomes a waste as API changes. graphql-tools has a mocking library that allows you to map values based on types or field names. Very useful, especially if synchronized with mocking library like faker.js or casual.js

Create or Update Database

Being that GraphQL is an abstraction that is somewhat geared towards UI requirements, there is no need to map a one-to-one schema between GraphQL schema and Database Schema. Through the resolver, we can morph and transform and even fetch extra data without being constricted with the database schema. This enables faster iteration and prototyping.

Dependencies

  • apollo-client: A simple yet functional GraphQL client.
  • body-parser: Node.js body parsing middleware
  • cors: middleware for dynamically or statically enabling CORS in express/connect applications
  • cssnano: A modular minifier, built on top of the PostCSS ecosystem.
  • express: Fast, unopinionated, minimalist web framework
  • graphql: A Query Language and Runtime which can target any service.
  • graphql-server-express: Production-ready Node.js GraphQL server for Express and Connect
  • graphql-tag: A JavaScript template literal tag that parses GraphQL queries
  • graphql-tools: A set of useful tools for GraphQL
  • knex: A batteries-included SQL query & schema builder for Postgres, MySQL and SQLite3 and the Browser
  • lodash: Lodash modular utilities.
  • normalize.css: A modern alternative to CSS resets
  • pg: PostgreSQL client - pure javascript & libpq with the same API
  • pretty-error: See nodejs errors with less clutter
  • react: React is a JavaScript library for building user interfaces.
  • react-apollo: React data container for Apollo Client
  • react-dom: React package for working with the DOM.
  • react-redux: Official React bindings for Redux
  • react-router: A complete routing library for React
  • redux: Predictable state container for JavaScript apps
  • redux-thunk: Thunk middleware for Redux.

Dev Dependencies

License

MIT

About

Docker + Hot Loading + Node + Express + PostgreSQL + Knex + GraphQL + React + Redux + React Router

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 86.9%
  • Makefile 6.0%
  • Shell 2.9%
  • Nginx 2.2%
  • CSS 1.4%
  • HTML 0.6%