/todo-graphql-nestjs

✅ A TODO GraphQL API boilerplate built with NestJS

Primary LanguageTypeScript

📝 Description

A TODO GraphQL API boilerplate

🎉 Features

  • TODOS: CRUD around TODOS
  • ORM: TypeORM on PostgreSQL
  • Graphql: TypeGraphQL
  • Cache System: type-cacheable
  • Logging: NestJS default logger
  • Sanitizer: class-sanitizer
  • E2E tests: SuperTest
  • Unit tests: Jest
  • Commit semantic: commitlint + husky
  • Code format and lint: eslint + prettier
  • Documentation: Compodoc

🧰 Installation

Prerequisites

  • Linux or macOS
  • Node v12 LTS
  • Globally yarn & nest commands
  • Docker

Install yarn packages before continue

yarn

Setting up PostgreSQL database

  • This is will make a new PostgreSQL running in the standard port 5432
  • Please shutdown any previous conflicting PostgreSQL instances before starting this
docker-compose up -d

Check the database is up

docker logs -f todo_pg

Check that you can log into a database with psql

docker exec -it todo_pg psql -U todo_pg_user todo_pg_db

View tables

\dt

Creating the initial database

Run initial migrations to set up initial database tables

yarn typeorm migration:run

⌨ Development

⚙ Running the app

# development
yarn start

# watch mode
yarn start:dev

# production mode
yarn start:prod

🎮 Playground & 🩺 Health check

After the application starts, go to http://localhost:$PORT/health to check health indicators statuses or http://localhost:$PORT/graphql to access graphql playground

Observartion: You must change $PORT for the port to be used in your environment

🧪 Running tests

Creating tests database Only integration tests are supported. Backend is spun up on a special database

Tests use their own database. To create it:

docker exec -it todo_pg psql -U todo_pg_user -c "create database todo_pg_db_test" todo_pg_db

Note that in backend/config/typeorm.config.ts the todo_db_test database is configured to synchronize TypeORM migrations automatically, unlike the development database.

# unit tests
yarn test

# e2e tests
yarn test:e2e

# test coverage
yarn test:cov

After executing yarn test:cov, the coverage folder will be generated with coverage details

📏 Lint

Linting codebase

# issues are automatically fixed
yarn lint

🧳 Migrations

Run typeorm CLI

Automatically generating migrations

You can generate migration files

  1. Update entity source code
  2. You have an up-to-date local development database
# creates a file under src/migrations/
yarn typeorm migration:generate -n MigrationName

Apply migrations against the local database

yarn typeorm migration:run

Check the result of migrations using psql command-line tool

docker exec -it todo_pg psql -U todo_pg_user todo_pg_db
\d 'todo'

📖 Documentation

Generating codebase documentation(served at http://127.0.0.1:8080)

yarn doc

📦 Building

Before building application to production, make sure environment variables are applied correctly

Building for production

yarn build

Running on production

yarn start:prod

✅ TODO

[ ] Add code of conduct file
[ ] Add docker section to make project working through docker
[ ] Add project files structure
[ ] Add issue template file
[ ] Add typeorm-seeding within seeds
[ ] Check if env variables are loading correctly using
schema-validation
[ ] Track errors in production. Use sentry.io or similar

Observation: Some TODOS are spread across the code and need to be fixed ASAP

💻 Code style

The current code style is following clean code, some design patterns and SOLID principles

🛠 Built with

  • compodoc - The missing documentation tool for your Angular application
  • jest - Jest is a delightful JavaScript Testing Framework with a focus on simplicity
  • nestjs - A progressive Node.js framework for building efficient, reliable and scalable server-side applications
  • supertest - Small progressive client-side HTTP request library, and Node.js module with the same API
  • typegraphql - Modern framework for GraphQL API in Node.js
  • typeorm - Amazing ORM for TypeScript and JavaScript (ES7, ES6, ES5)

👷 Authors

See also the list of contributors who participated in this project

📝 License

Copyright © 2020 Lucas Silva
This project is MIT licensed