NodeJs GraphQL API applying CQRS and DDD patterns, built with CI.
The goal of this GraphQL API is get the location and all the details and comments of campings. You can have access to the API here camps-api.herokuapp.com/graphql
Getting Started • Queries and Mutations • Built With • Build • Tests • Coding Standard • CI and Deployment • License
To install and run the API you need only Docker Compose. Please follow the official documentation to install it on your environment.
Clone the project and run the default installation:
git clone https://github.com/christophe-chausseray/camps-graphql-api.git
cd camps-api
make up
Your docker containers should have been successfully built and run the api directly.
You can now access to your local GraphQL Playground on http://0.0.0.0:3000/graphql to test the API.
You can also uninstall the application with :
make down
It will stop and unmount the docker containers.
With the Camps API, you can make queries and mutations to :
- Get a list of campings
- Get the information details of one camping
- Get a list of comments for a camping
- Add a new comment for a camping
You can get all the information about how to make those queries and mutation in the section Docs and Schema of your GraphQL Playground.
I would like to get the list of campings with the id, name and location (longitude / latitude) of each one.
If you want to build your application in production environment, you need to run :
make build
P.S : It will also run the linter and test tasks. If you want to run the build without it, you need to run :
docker-compose exec api yarn build:ts
This API is automated tested following the Test Pyramid : Unit tests, Integration tests and End-to-End tests.
Those tests can be run with :
make test
Code and folder structure follow Domain Driven Design principle and Hexgonal architecture.
src
\
|\ Application `Contains handlers to handle the use-cases apply on the Domain. It adapts the request from the Infrastructure layer to the Domain layer.`
|
|\ Domain `The system business logic layer (Read / Write Models, Value Objects, Exceptions)`
|
|\ Infrastructure `It contains the code which communicating with third-party libraries and used by the application.(Persistence, Query, API Request etc)`
In this project, I used the principle of CQRS to separate the information we read from the system and the information we write in the system.
For exemple, when the user would like to list the comments for a camping the system will use a query handler which will return one read model. Whereas, when the user would like to add a comment for this camping the system will use a command handler which will create a write model before to persist it in DB.
This project handles the CI and deployment with Github Actions on Heroku.
The build and deploy workflows can be found in the .github/workflows/
directory.
The CI build will be run on the branch following the pattern feature/**
or fix/**
.
It will execute the linter and the test to check if the code is following the coding style of the application and if it doesn't break anything.
Christophe Chausseray · Linkedin