Hacker News Clone React/GraphQL
React - (UI Framework)
GraphQL - (Web Data API)
Apollo - (GraphQL Client/Server)
Next - (Routing, SSR, Hot Module Reloading, Code Splitting, Build tool uses Webpack)
TypeScript - (Static Types)
Webpack - (Module Bundler)
PostCSS - (CSS Processing)
Node.js - (Web Server)
Express - (Web App Server)
Passport - (Authentication)
ESLint - (Coding Best Practices/Code Highlighting)
Jest - (Tests)
Docker - (Container Deployment)
Optional - Yarn or Pnpm Package Manager - (Better Dependencies)
- Declarative UI - (
- Static Typing (
- GraphQL Fragment Colocation - (
- Prefetch Page Assets - (
- Universal JS - (
- Declarative GraphQL Schema - (
- GraphQL Query Batching - (
- GraphQL Stored Queries - (
- Easy GraphiQL Include - (
- Local Authentication Strategy - (
- Server Side Rendering - (
- Code Splitting - (
- Build to Static Website - (
- Container Based Runtime - (
- Hot Module Reloading - (
- Snapshot Testing - (
- GraphQL Playground - (
- Faster Package Install - (
- JS/TS Best Practices - (
server.ts is the entry point. It uses Express and passes requests to Next. Next SSR renders the pages using
getServerSideProps() hook from Apollo helper. Therefore the app makes GraphQL requests on the client or server.
When the client loads the page it preloads next pages code from any
<Link href="/">. When the client navigates to the next page it only needs to make one GraphQL query to render. Great!
Each web page has a React component in
pages. Server code is in
server. Shared code that runs on client or server is in
src. Do not import from
src to avoid running code in the wrong environment.
The project root contains config files such as TypeScript, Babel, ESLint, Docker, Flow, NPM, Yarn, Git.
How To Start
One Click Download & Run
You can download and run the repo with one command to rule them all:
git clone https://github.com/clintonwoo/hackernews-react-graphql.git && cd hackernews-react-graphql && npm install && npm start
Running the app in dev mode is fully featured including hot module reloading:
To run in production mode:
npm run build:prod && npm run start:prod
The project runs out of the box with default settings (
/src/config.ts). You can include a .env file in your project root to configure settings (this is the 'dotenv' npm package). The .env file is included in .gitignore.
How To Test
This project uses Jest and can do snapshot testing of React components. Whenever a component is changed, please update the snapshots using
npm test -- -u or
npx jest --updateSnapshot.
How To Build For Deployment
npm run build:prod: NextJS app with entry point
server.ts that uses Node.js/Express. Uses TypeScript compiler to transpile project src to build.
npm run build-docker Docker Container: Builds a docker container using Dockerfile.
Static Website (Optional)
NextJS lets us make a powerful static website but you need to consider if you need server side rendering.
npm run build-static-website: Builds static website to
/build/static. Use a static web server eg. NGINX/Github Pages.
Pull requests are welcome. File an issue for ideas, conversation or feedback.
After you ★Star this project, follow @ClintonDAnnolfo on Twitter.