Git Product home page Git Product logo

josephgodwinkimani / nestjs-graphql-prisma Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 0.0 275 KB

Nest.js Hybrid Application (HTTP server with microservice listeners) with GraphQL (schema first), Prisma, MySQL (easily replaceble), MongoDB, Jest, Docker

JavaScript 1.86% TypeScript 98.14%
nestjs-graphql nestjs-microservices nestjs-prisma grpc mqtt nestjs-kafka nestjs-rabbitmq docker-compose nestjs-http cockroachdb

nestjs-graphql-prisma's Introduction

Nest Logo

A progressive Node.js framework for building efficient and scalable server-side applications.

NPM Version Package License NPM Downloads CircleCI Coverage Discord Backers on Open Collective Sponsors on Open Collective Support us

Simple Blog API ( CRUD users, users CRUD posts, users upload files )

Prisma GraphQL schema-first 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 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
# run mongodb, mongo express container
$ docker-compose -f docker-compose-mongo.yml up -d
# run mysql, phpmyadmincontainer
$ docker-compose up -d
  1. Install dependencies: npm install
  2. Generate TypeScript type definitions for the GraphQL schema: npm run generate:typings
  3. Generate a type-safe client to interact with your database: npm run prisma:gen
  4. Create mariadb/mysql database and create tables: npm run prisma:push
  5. Start server: npm run start:dev

Test

# 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 to access the GraphQL Playground. See here for more.

Create a New User

mutation {
  createUser(input: { name: "Godwin Kimani", email: "[email protected]"}) {
    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: "[email protected]" }) {
    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
  }
}

Related Projects

nestjs-graphql-prisma's People

Contributors

josephgodwinkimani avatar renovate[bot] avatar

Watchers

 avatar

nestjs-graphql-prisma's Issues

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Rate-Limited

These updates are currently rate-limited. Click on a checkbox below to force their creation now.

  • chore(deps): update dependency supertest to v6.3.4
  • chore(deps): update dependency ts-jest to v29.1.2
  • chore(deps): update mongo-express docker tag to v1.0.2
  • fix(deps): update dependency @nestjs/mongoose to v10.0.4
  • fix(deps): update dependency class-validator to v0.14.1
  • chore(deps): update dependency @nestjs/cli to v10.3.2
  • chore(deps): update dependency eslint-plugin-prettier to v5.1.3
  • chore(deps): update dependency typescript to v5.4.2
  • fix(deps): update dependency @apollo/server to v4.10.1
  • fix(deps): update dependency @nestjs/apollo to v12.1.0
  • fix(deps): update dependency @nestjs/config to v3.2.0
  • fix(deps): update dependency @nestjs/graphql to v12.1.1
  • fix(deps): update nest monorepo (@nestjs/common, @nestjs/core, @nestjs/microservices, @nestjs/platform-express, @nestjs/schematics, @nestjs/testing)
  • chore(deps): update dependency @types/supertest to v6
  • chore(deps): update dependency ts-morph to v22
  • chore(deps): update typescript-eslint monorepo to v7 (major) (@typescript-eslint/eslint-plugin, @typescript-eslint/parser)
  • ๐Ÿ” Create all rate-limited PRs at once ๐Ÿ”

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

Detected dependencies

docker-compose
docker-compose-mongo.yml
  • mongo-express 1.0.0-18-alpine3.18
docker-compose.yml
npm
package.json
  • @apollo/server 4.9.5
  • @nestjs/apollo 12.0.11
  • @nestjs/common ^10.0.0
  • @nestjs/config 3.1.1
  • @nestjs/core ^10.0.0
  • @nestjs/graphql 12.0.11
  • @nestjs/mapped-types *
  • @nestjs/microservices 10.2.10
  • @nestjs/mongoose 10.0.2
  • @nestjs/platform-express ^10.0.0
  • @prisma/client 4.16.2
  • class-transformer 0.5.1
  • class-validator 0.14.0
  • graphql 16.8.1
  • graphql-subscriptions 2.0.0
  • mongoose 8.0.1
  • reflect-metadata ^0.1.13
  • rimraf 5.0.5
  • rxjs ^7.8.1
  • @nestjs/cli ^10.0.0
  • @nestjs/schematics ^10.0.0
  • @nestjs/testing ^10.0.0
  • @types/express ^4.17.17
  • @types/jest ^29.5.2
  • @types/multer 1.4.11
  • @types/node ^20.3.1
  • @types/supertest ^2.0.12
  • @typescript-eslint/eslint-plugin ^6.0.0
  • @typescript-eslint/parser ^6.0.0
  • eslint ^8.42.0
  • eslint-config-prettier ^9.0.0
  • eslint-plugin-prettier ^5.0.0
  • jest ^29.5.0
  • prettier ^3.0.0
  • prisma ^4.15.0
  • source-map-support ^0.5.21
  • supertest ^6.3.3
  • ts-jest ^29.1.0
  • ts-loader ^9.4.3
  • ts-morph ^20.0.0
  • ts-node ^10.9.1
  • tsconfig-paths ^4.2.0
  • typescript ^5.1.3

  • Check this box to trigger a request for Renovate to run again on this repository

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.