Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/josephgodwinkimani/nestjs-graphql-prisma
Nest.js Hybrid Application (HTTP server with microservice listeners) with GraphQL (schema first), Prisma, MySQL (easily replaceble), MongoDB, Jest, Docker
https://github.com/josephgodwinkimani/nestjs-graphql-prisma
cockroachdb docker-compose grpc mongoose mqtt mysql nestjs-graphql nestjs-http nestjs-kafka nestjs-microservices nestjs-prisma nestjs-rabbitmq postgresql
Last synced: about 2 months ago
JSON representation
Nest.js Hybrid Application (HTTP server with microservice listeners) with GraphQL (schema first), Prisma, MySQL (easily replaceble), MongoDB, Jest, Docker
- Host: GitHub
- URL: https://github.com/josephgodwinkimani/nestjs-graphql-prisma
- Owner: josephgodwinkimani
- Created: 2023-12-07T13:05:42.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2024-11-04T08:46:29.000Z (about 2 months ago)
- Last Synced: 2024-11-04T09:31:55.721Z (about 2 months ago)
- Topics: cockroachdb, docker-compose, grpc, mongoose, mqtt, mysql, nestjs-graphql, nestjs-http, nestjs-kafka, nestjs-microservices, nestjs-prisma, nestjs-rabbitmq, postgresql
- Language: TypeScript
- Homepage:
- Size: 271 KB
- Stars: 2
- Watchers: 1
- Forks: 1
- Open Issues: 11
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
[circleci-image]: https://img.shields.io/circleci/build/github/nestjs/nest/master?token=abc123def456
[circleci-url]: https://circleci.com/gh/nestjs/nest
A progressive Node.js framework for building efficient and scalable server-side applications.
### Simple Blog API ( CRUD users, users CRUD posts, users upload files )
> [Prisma](https://docs.nestjs.com/recipes/prisma) [GraphQL schema-first](https://docs.nestjs.com/graphql/quick-start#schema-first) [Hybrid application](https://docs.nestjs.com/faq/hybrid-application)
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](https://www.prisma.io/docs/getting-started) 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}
```### Installation
1. Run multi-container Docker applications
```bash
# run mongodb, mongo express container
$ docker-compose -f docker-compose-mongo.yml up -d
# run mysql, phpmyadmincontainer
$ docker-compose up -d```
2. Install dependencies: `npm install`
3. Generate TypeScript type definitions for the GraphQL schema: `npm run generate:typings`
4. Generate a type-safe client to interact with your database: `npm run prisma:gen`
5. Create mariadb/mysql database and create tables: `npm run prisma:push`
6. Start server: `npm run start:dev`## Test
```bash
# unit tests
$ npm run test# e2e tests
$ npm run test:e2e# test coverage
$ npm run test:cov
```### Graphql Playground
When the application is running, you can go to [http://localhost:3001/graphql](http://localhost:3001/graphql) to access the GraphQL Playground. See [here](https://docs.nestjs.com/graphql/quick-start#playground) for more.
**Create a New User**
```
mutation {
createUser(input: { name: "Godwin Kimani", email: "[email protected]"}) {
id
name
}
}
```**List all Existing Users**
```
query {
users {
id
name
}
}
```**Retrieve an Existing User**
```
query {
user(id: "3f234751-1819-4d96-ad0b-29840796806d") {
id
name
}
}
```**Update an Existing User**
```
mutation {
updateUser(input: { id: "3f234751-1819-4d96-ad0b-29840796806d", name: "James Koome", email: "[email protected]" }) {
id
name
}
}
```**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
}
}
```## Related Projects
- [Refine Boilerplate for Web (PWA), Desktop and Mobile](https://github.com/josephgodwinkimani/refine-starter) — 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).
-