- Owner & pet's GraphQL API
- Test coverage
- Logging in the file by
winston
- Docker deploy
- Used filesystem database by
nedb
- Embedded initial data set
- No transpilers, just vanilla javascript
- ES2017 latest features like Async/Await
- Eslint configured
- Node v10.15.0+ or Docker
- npm
git clone [email protected]:joynal/pet-house.git
cd pet-house
Install packages:
$ npm i
Running in development:
npm run dev
Running in production
npm run start
# run container in development
npm run docker:dev
# run container in production
npm run docker:prod
Wait a couple of seconds while docker container is starting. The application container will start in the background.
Get container id by running:
docker ps -a
Stop docker container:
docker stop <CONTAINER_ID>
$ npm run test
All logs will be stored & synced from docker container into the logs
directory. File rotation is enabled by date wise.
To view real-time logging from docker:
docker logs -f <CONTAINER_ID>
Replace my docker username & ssh server with yours:
vim deploy.sh
Deploy script:
npm run deploy
Let's play with the backend. Go to host URL, in my case; it is http://localhost:4000/
Owner's API:
// get the list of owners
query getOwners {
owners(filter: { limit: 20, offset: 0 }) {
_id
name
address
phone
email
pets {
_id
name
}
}
}
// get a owner details
query getOwnerDetails {
owner(id: "imT1p0oJ3gU0Bo3n") {
_id
name
address
phone
email
pets {
_id
name
}
}
}
// create an owner
mutation CreateOwner {
addOwner(
input: {
name: "Joynal"
email: "[email protected]"
address: "Dhaka"
}
) {
name
email
address
}
}
// update a owner
mutation EditOwner {
editOwner(id: "lwdoL7fUYFvuwVHH", input:{
phone: "0999346",
address: "Rajshahi",
}) {
_id
name
address
phone
email
}
}
// delete a owner
mutation DeleteOwner {
deleteOwner(id: "z4CxyHolWfHmm1tq") {
_id
}
}
Pet's API:
// get list of pets
query getPets {
pets(filter: { limit: 20, offset: 0 }) {
_id
name
color
breed
ownerId
}
}
// get a pet details
query getPetDetails {
pet(id: "4S2AOCNKQ3NaubWb") {
_id
name
color
breed
ownerId
}
}
// create a pet
mutation CreatePet {
addPet(input:{
name: "Kutti"
age: 2
color: "White"
breed: "Collins"
ownerId: "Rmplca4avD8yurgP"
}) {
name
color
breed
owner {
name
}
}
}
// update a pet
mutation EditPet {
editPet(id: "2eabYdJRPhMMNRUX", input: {
name: "Bulldog",
color: "black",
}) {
_id
name
color
}
}
// delete a pet
mutation DeletePet {
deletePet(id: "JkVbIktQ0V1vxCKR") {
_id
}
}
Data set already embedded into the filesystem. In case you want to regenerate it, here is how to do it.
$ node test/seed.js
Just remove your changes, you can easily do it by git:
git checkout .
Joynal Abedin - Joynal
This project is licensed under the MIT License - see the license file for details