NestJS, GraphQL, Prisma, MySQL, Typescript, Jest, Supertest를 이용한 HR API
- node >=18.17.1
- npm >=9.6.7
$ npm install# development mode
$ npm run start
# watch mode
$ npm run start:dev
# production mode
$ npm run start:prod# unit and contract tests under src/**/*.spec.ts
$ npm run test
# unit tests with watch mode
$ npm run test:watch
# unit tests with coverage
$ npm run test:cov
# mocked resolver e2e tests under test/*.e2e-spec.ts
$ npm run test:e2e
# DB-backed release-gate e2e tests against a migrated and seeded MySQL database
$ npm run test:e2e:db
# production build
$ npm run build
# typecheck without emitting files
$ npx tsc --noEmit --pretty false
# eslint check; note package script runs eslint with --fix
$ npx eslint "{src,apps,libs,test}/**/*.ts"npm run testruns Jest withrootDir: src. It includes unit tests and contract tests such as:src/common/graphql-schema-contract.spec.tsfor the public GraphQL schema snapshot and high-risk schema assertions.src/common/nullability-contract.spec.tsfor Prisma-backed GraphQL and DTO nullability expectations.src/common/utils/prisma-mutation-services.spec.tsandsrc/common/utils/prisma-query-policy-services.spec.tsfor cross-service Prisma behavior.
npm run test:e2eruns the resolver e2e specs intest/*.e2e-spec.ts. These tests intentionally use mocked domain services plus a mockedPrismaServicethroughtest/e2e-test-utils.ts, so they do not requireDATABASE_URLor a running MySQL instance. They verify GraphQL/resolver wiring and request bootstrap behavior, not real database persistence.npm run test:e2e:dbrunstest/*.db-e2e.tsagainst the realAppModule, realPrismaService, and theDATABASE_URLMySQL database. It does not mock domain services or Prisma. This profile is intended as an explicit release gate for Prisma/MySQL integration behavior.
The DB-backed profile requires a dedicated, migrated, and seeded MySQL database. Do not point this command at a shared production database because the test creates and removes a temporary user.
# example setup for a disposable database
$ export DATABASE_URL="mysql://root:password@127.0.0.1:3306/hrms_e2e"
$ export JWT_SECRET="test-secret"
$ npx prisma migrate deploy
$ npx prisma db seed
$ npm run test:e2e:dbThe DB-backed test logs in with the seeded alice@prisma.io account, runs
protected GraphQL operations with a real JWT, verifies real user persistence, and
asserts that passwords are not exposed in GraphQL responses.
The committed GraphQL schema snapshot lives at:
src/common/__snapshots__/graphql-schema-contract.spec.ts.snap
Use it as a schema-diff gate when changing public GraphQL contracts:
# run the schema contract test
$ npm test -- --runInBand src/common/graphql-schema-contract.spec.ts
# intentionally update the snapshot after reviewing the schema diff
$ npm test -- --runInBand src/common/graphql-schema-contract.spec.ts -uThe schema contract test builds the resolver schema without starting the
database-backed AppModule. It snapshots a lexicographically sorted schema and
asserts key contracts directly, including:
User.passwordis not exposed on the publicUserobject type.loginUserremains present as the auth mutation entrypoint.- Top-level list queries expose
skipandtake. - Relation list fields expose
skipandtake.
Update the snapshot only when the GraphQL contract change is intentional and the diff has been reviewed.
# generate prisma client
$ npx prisma generate
# database migration
$ npx prisma db seed --preview-feature
# run migration
$ npx prisma migrate dev -name init
# revert migration
$ npx run migrate resetPORT=3000
DATABASE_URL="mysql://username:password@localhost:3306//hrms?schema=public"
JWT_SECRET=MDBjMWJlMzc4M2JhNGExY2FmNTRkZmU0NjlhNTRjYmY=👤 Changhoon Jee chjee71@gmail.com
- Github: @chjee
Give a ⭐️ if this project helped you!
This README was generated with ❤️ by readme-md-generator