- Nest: Nest is a framework for building efficient, scalable Node.js server-side applications.
- Express: a well-known minimalist web framework for node.
- GraphQL
- Apollo
- Prisma: ORM
- pnpm: Package Manager
https://www.npmjs.com/package/npm-check-updates
ncu
pnpm format
-
Run on local
-
Install dependencies
pnpm install
-
Start database.
docker-compose up -d postgres
or use local postgresql
psql postgres CREATE USER nest_graphql_training WITH PASSWORD 'nest_graphql_training'; ALTER USER nest_graphql_training CREATEDB; ALTER DATABASE nest_graphql_training OWNER TO nest_graphql_training;
-
Prepare schema
npx prisma migrate dev --name init
-
Run the app.
# development $ pnpm run start # watch mode $ pnpm run start:dev # production mode $ pnpm run start:prod
-
-
Run with docker
docker compose up --wait
-
Send
mutation
request from http://localhost:3000/graphqlmutation test { createUser( name: "john", email: "john@email.com", password: "password", hobby: "programming" ) { registeredAt, id, name, hobbies { id, name } } }
or via curl
curl 'http://localhost:3000/graphql' -H 'Accept-Encoding: gzip, deflate, br' -H 'Content-Type: application/json' -H 'Accept: application/json' -H 'Connection: keep-alive' -H 'DNT: 1' -H 'Origin: http://localhost:3000' --data-binary '{"query":"mutation test {\n createUser(\n name: \"bob\",\n email: \"bob@email.com\",\n password: \"password\",\n hobby: \"cooking\"\n ) {\n registeredAt,\n id,\n name,\n hobbies {\n id,\n name\n }\n }\n}"}' --compressed {"data":{"createUser":{"registeredAt":"2023-03-18T23:35:57.467Z","id":4,"name":"bob","hobbies":[{"id":2,"name":"cooking"}]}}}
-
Query
request from http://localhost:3000/graphqlquery hobby { hobbies { id, name, } }
You can send via curl:
curl 'http://localhost:3000/graphql' -H 'Accept-Encoding: gzip, deflate, br' -H 'Content-Type: application/json' -H 'Accept: application/json' -H 'Connection: keep-alive' -H 'DNT: 1' -H 'Origin: http://localhost:3000' --data-binary '{"query":"query hobby {\n hobbies {\n id,\n name,\n }\n}"}' --compressed {"data":{"hobbies":[{"id":1,"name":"programming"}]}}
# unit tests
$ pnpm run test
# e2e tests
$ pnpm run test:e2e
# test coverage
$ pnpm run test:cov