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.
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
To install Node Modules run un in your terminal
$ npm install
In order to build our Dockers Containers you need run this command:
$ npm run docker:build
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
# production mode
$ npm run start:prod
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
}
# unit tests
$ npm run test
# e2e tests
$ npm run test:e2e
# test coverage
$ npm run test:cov