A progressive Node.js framework for building efficient and scalable server-side applications.
This hybrid project uses GraphQL API query language for clean responses, TCP transport layer for microservice, @nestjs/testing
which uses jest for unit testing and MySQL as the relational database and MongoDB as no-sql database for constantly changing or growing data such as posts.
To connect other microservices uncomment examples in main.ts
, replace jest with vitest and to use a different database, check the Prisma docs e.g.
to use CockroachDB
// schema.prisma
datasource db {
provider = "cockroachdb"
url = env("DATABASE_URL")
}
// docker-compose.yml
cockroachdb:
image: cockroachdb/cockroach
restart: always
ports:
- "26257:26257"
- "8080:8080"
command: start-single-node --cluster-name=node1 --logtostderr=WARNING --log-file-verbosity=WARNING --insecure
environment:
- COCKROACH_USER=${DATABASE_USER}
- COCKROACH_PASSWORD=${DATABASE_PASSWORD}
- Run multi-container Docker applications
# run mongodb, mongo express container
$ docker-compose -f docker-compose-mongo.yml up -d
# run mysql, phpmyadmincontainer
$ docker-compose up -d
- Install dependencies:
npm install
- Generate TypeScript type definitions for the GraphQL schema:
npm run generate:typings
- Generate a type-safe client to interact with your database:
npm run prisma:gen
- Create mariadb/mysql database and create tables:
npm run prisma:push
- Start server:
npm run start:dev
# unit tests
$ npm run test
# e2e tests
$ npm run test:e2e
# test coverage
$ npm run test:cov
When the application is running, you can go to http://localhost:3001/graphql to access the GraphQL Playground. See here for more.
Create a New User
mutation {
createUser(input: { name: "Godwin Kimani", email: "josephgodwink90@aol.com"}) {
id
name
email
}
}
List all Existing Users
query {
users {
id
name
email
}
}
Retrieve an Existing User
query {
user(id: "3f234751-1819-4d96-ad0b-29840796806d") {
id
name
email
}
}
Update an Existing User
mutation {
updateUser(input: { id: "3f234751-1819-4d96-ad0b-29840796806d", name: "James Koome", email: "josephgodwink90@aol.com" }) {
id
name
email
}
}
Create a New Post
mutation {
createPost(input: { title: "Example Title", text: "Example Content", authorId: "3f234751-1819-4d96-ad0b-29840796806d"}) {
id
title
text
}
}
List all Existing Posts
query {
posts {
id
title
text
isPublished
author {
name
}
# Add other fields as needed
}
}
Retrieve a Single Post
query {
post(id: "6c248661-43a7-4b77-9e4d-11978418fc3e") {
id
title
text
author {
name
}
}
}
Update an Existing Post
mutation {
updatePost(input: { id: "265bb380-ebeb-41e3-8670-32eec5c5fa7c", title: "Post on A.I.", text: "Yes Other Example Content", isPublished: true }) {
id
title
text
isPublished
}
}
Delete an Existing Post
mutation {
deletePost(id: "265bb380-ebeb-41e3-8670-32eec5c5fa7c") {
id
}
}
- Refine Boilerplate for Web (PWA), Desktop and Mobile — A Cross-Platform starter template for Refine.dev that utilizes the Simple REST data provider to fetch and display data from a REST API (can easily replace with graphql data provider).