Skip to content

A Simple CRUD Operations with GraphQL, Nest.js and MongoDB using Docker

Notifications You must be signed in to change notification settings

LeoCR/nest-js-graphql-mongodb

Repository files navigation

Nest Logo Docker Compose Docker Logo GraphQL Logo

Description

This project was built in with Nest.js framework, the purpose of this project is understand how we can integrate Nest.js with MongoDB, GraphQL and Docker in Order to have CRUD Operations.

This project is about some products of any type and was created for educational purposes.

Requirements

Configuration

You need to create .env file whith these Keys(PD: Feel free to change these values):

PORT=3003
DB_URL=mongodb://YOUR_DB_USERNAME:YOUR_DB_PASSWORD@
DB_HOST=localhost
DB_USERNAME=YOUR_DB_USERNAME
DB_PASSWORD=YOUR_DB_PASSWORD
DB_PORT=27018
DB_NAME=YOUR_DB_NAME

Installation

To install Node Modules run un in your terminal

$ npm install

Run the Docker Container

In order to build our Dockers Containers you need run this command:

$ npm run docker:build

Running in Development mode

If you need to run the app in Development mode first you need to stop the container named: nest-mongo-api-container then you will need to start the container named nest-app-db-products-container , then you can run this command:

# development
$ npm run start:dev

Running in Poduction mode

# production mode
$ npm run start:prod

GraphQL

Once that you are running the Docker Containers you will have a GraphQL API located in this URL: http://localhost:3003/graphql.

type Product {
  # ID of the Product
  _id: String!
  # Name of the Product
  name: String!
  # Main image URL of the Product ,size minimun 320px width and 200px height
  image: String!
  # Description of the Product
  description: String!
  # Quantity of the Product
  quantity: Int!
  # Price of the Product
  price: Float!
}
type Query {
  products: [Product!]!
  product(id: String!): Product!
}
type Mutation {
  createProduct(createProductInput: CreateProductInput!): Product!
  updateProduct(id: String!, updateProductInput: UpdateProductInput!): Product!
  removeProduct(id: String!): Product!
}
input CreateProductInput {
  # The name of the product
  name: String!
  # Main image URL of the Product ,size minimun 320px width and 200px height
  image: String!
  # The description of the product
  description: String!
  # The quantity of the product
  quantity: Int!
  # The price of the product
  price: Float!
}

input UpdateProductInput {
  # The name of the product
  name: String
  # Main image URL of the Product ,size minimun 320px width and 200px height
  image: String
  # The description of the product
  description: String
  # The quantity of the product
  quantity: Int
  # The price of the product
  price: Float
}

Test

# unit tests
$ npm run test

# e2e tests
$ npm run test:e2e

# test coverage
$ npm run test:cov

About

A Simple CRUD Operations with GraphQL, Nest.js and MongoDB using Docker

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published