iTask GraphQL server
- iTask GraphQL Server
- Table of contents
- Features
- Setup
- Dockerize
- Setup GitHub Actions
- Scripts
- 1. Development
- 2. Build
- 3. Generate type validators
- 4. Generate GraphQL TypeScript shared types
- 5. Generate both GraphQL TypeScript shared types and type validators
- 6. Generate Prisma client
- 7. Migrate Prisma dev environment
- 8. Deploy Prisma schema
- 8. Git commit with commitizen CLI
- 9. Backup database
- 10. Restore database
- 11. Restore database automatically on Docker
- 12. Unit test
- 13. Test coverage
- References
- RESTful API
- Apollo GraphQL server
- Full TypeScript codebase
- Unit test with Jest
- Dockerize
- Wait for
PostgreSQL
readiness before starting NodeJS server (on the Docker environment)
-
Prepare ENV files
Base on
.env.example
file, define your environment variablescp .env.example .env
-
Install
node_modules
- Using
npm
:
npm install
- Using
yarn
:
yarn
- Using
Start dev server
-
Using
npm
:npm run dev:server
-
Using
yarn
:yarn dev:server
-
Build production
- Using
npm
:
npm run build
- Using
yarn
:
yarn build
- Using
-
Start production server using PM2
- Using
npm
:
npm run start:prod
- Using
yarn
:
yarn start:prod
- Using
-
Prepare ENV files
Base on
.docker.dev.env.example
file, define your environment variablescp .docker.dev.env.example .docker.dev.env
-
Start docker compose (
docker-compose.yml & docker-compose.dev.yml
)./scripts/dev up -d
-
Stop docker compose (
docker-compose.yml & docker-compose.dev.yml
)./scripts/dev stop
-
Prepare ENV files
Base on
.docker.prod.env.example
file, define your environment variablescp .docker.prod.env.example .docker.prod.env
-
Start docker compose (
docker-compose.yml & docker-compose.prod.yml
)./scripts/prod up -d
-
Stop docker compose (
docker-compose.yml & docker-compose.prod.yml
)./scripts/prod stop
There are 2 (two) action workflows:
-
test
This will be triggered automatically on every open Pull request to
master
branchThis workflow runs test coverage script during the invocation
-
ci
This will be triggered automatically on every open Pull request to
master
branchThis workflow runs:
- Test coverage
- Upload test coverage to
Codecov
- Release new version
Required steps:
- Register your repository with
Codecov
to getCODECOV_TOKEN
- Configure repository secrets with name
CODECOV_TOKEN
Run & develop
-
Using
yarn
:yarn dev:server
-
Using
npm
:npm run dev:server
Build production source code
-
Using
yarn
:yarn build
-
Using
npm
:npm run build
Generate TypeScript validator files
-
Using
yarn
:yarn codegen:validators
-
Using
npm
:npm run codegen:validators
Generate TypeScript shared types from GraphQL
-
Using
yarn
:yarn codegen:gql
-
Using
npm
:npm run codegen:gql
-
Using
yarn
:yarn codegen
-
Using
npm
:npm run codegen
Generate Prisma client (
./node_modules/.prisma
)
-
Using
yarn
:yarn prisma:generate
-
Using
npm
:
npm run prisma:generate
Migrate Prisma schema and apply to database
-
Using
yarn
:yarn prisma:dev
-
Using
npm
:npm run prisma:dev
Apply Prisma schema to production environment
-
Using
yarn
:yarn prisma:deploy
-
Using
npm
:npm run prisma:deploy
Commit CLI command with interactive
-
Using
yarn
:yarn commit
-
Using
npm
:npm run commit
pg_dump -v -U $POSTGRES_USER -O -d $POSTGRES_ITASK_DB > path/to/sql/file
psql -v -U $POSTGRES_USER -d $POSTGRES_ITASK_DB < path/to/sql/file
- Prepare a SQL backup file (named
$POSTGRES_ITASK_DB.sql
with$POSTGRES_ITASK_DB
is your defined environment variable) - Place the SQL backup file under
./backup
folder. - When docker running up, this backup file will be restored automatically.
-
Using
npm
:npm run test
-
Using
yarn
:yarn test
As configuration from ./jest.config.ts
Jest will fail if there is less than 90%
branch, line, and function coverage, or if there are more than 10
uncovered statements:
-
Using
npm
:npm run test -- --coverage
-
Using
yarn
:yarn test --coverage