A GraphQL API using NestJS that does basic CRUD operations into a Postgres database and that sends events into a RabbitMQ queue
- Docker installed
- Node package manager installed npm, yarn, pnpm
$ pnpm install
Run postgres
$ docker run --name rabbitmq-nestjs-edge -e POSTGRES_PASSWORD=mypassword -p 5432:5432 -d postgres
Copy the .env.example
file and call in .env
. Add the database URL and set the correct password.
Run RabbitMQ server
$ docker run -it --rm --name rabbitmq -p 5672:5672 -p 15672:15672 rabbitmq:3.13-management
Open another terminal window and run NestJS
$ pnpm run start
or in dev mode
$ pnpm run start:dev
Now open localhost:3000/graphql
for the graphql playground.
- Add the queries and mutation
- Add the Query variables
- Execute!
Queries and Mutation
mutation createEdge($createEdgeInput: CreateEdgeInput!) {
createEdge(createEdgeInput: $createEdgeInput) {
node1_alias
node2_alias
id
created_at
updated_at
}
}
query getEdges {
getEdges {
id
node1_alias
node2_alias
created_at
updated_at
edge_peers
}
}
query getEdge($getEdgeInput: GetEdgeInput!) {
getEdge(getEdgeInput: $getEdgeInput) {
id
node1_alias
node2_alias
created_at
updated_at
edge_peers
}
}
Query variables
{
"createEdgeInput": {
"node1_alias": "13",
"node2_alias": "12"
},
"getEdgeInput": {
"id": "e5751d1-1229-4303-9160-daafda770b4a"
}
}
# development
$ pnpm run start
# watch mode
$ pnpm run start:dev
# production mode
$ pnpm run start:prod
# unit tests
$ pnpm run test
# e2e tests
$ pnpm run test:e2e
# test coverage
$ pnpm run test:cov
Nest is an MIT-licensed open source project. It can grow thanks to the sponsors and support by the amazing backers. If you'd like to join them, please read more here.
Nest is MIT licensed.
- Author - Thomas Guntenaar