A NodeJs / TypeScript application boilerplate with Federated 2 GraphQL.
- It contains a mechanism to pull all the data from an unpaginated Open Charge Map API.
- It uses MongoDB as a persistent database layer with Mongoose as an ODM.
- The data is then queryable through GraphQL in relay-style pagination.
- It can be run with Docker and Docker-Compose containerization software.
- It has some end-to-end and unit tests written using Jest.
- It uses ESLint, Prettier, CommitLint, and Husky for maintaining code quality.
- It uses Winston for logging.
- It uses New Relic for error logging, application performance monitoring, and log monitoring.
-
Create an application that pulls current charging station data from Open Charge Map API and then persists the data in MongoDB.
- The following fields are to be imported from Open Charge Map API:
- operatorInfo
- statusType
- addressInfo
- connections
- The following fields are to be imported from Open Charge Map API:
-
The service pulls the data and updates our own database. It shall update the database only in case of changes in the pulled data.
-
There is one entity - Socket. It represents charging stations in our database.
-
There are two graphql queries - Socket and Sockets.
-
Clone from GitHub
git clone https://github.com/the-vishal-kumar/nodejs-typescript-federated-graphql-boilerplate.git
-
Setup Docker and Docker-Compose
- Install
docker
anddocker-compose
on your machine - Copy
docker-compose.sample.yml
asdocker-compose.yml
- Install
-
Install dependencies using npm
cd nodejs-typescript-federated-graphql-boilerplate npm i
-
Set environment variables
-
Copy
.env.sample
to the root directory as.env
.-
Put the value of
OPEN_CHARGE_MAP_API_KEY
.- Leaving it empty won't prevent the application from starting/running, but the polling won't work.
- The application will be able to serve queries from already polled data (which will be empty if the application is started without a key).
-
(Optional) Put the value of
NEW_RELIC_LICENSE_KEY
. Generate a key from here.
-
-
-
Execute the command from the root directory to start the application
npm start
-
Some end-to-end and unit tests are included in
src/test
directory for the socket subgraph -
Tests are run using Jest
-
Execute the command from the root directory to run the tests
npm test
- Import Postman collection and environment variable
- Language - NodeJs | TypeScript
- GraphQL | Federated GraphQL
- MongoDB
- Containerization Software - Docker | Docker-Compose
- Version Control - Git
- A feature branch is created from the dev branch, and after completion of the code, a PR is generated for the dev branch
- If changes are requested by a reviewer on Github, then the person who has made the PR makes appropriate changes. The reviewer reviews again and marks the comments as resolved
- If there are no new changes required, then PR is merged with the dev branch
- Credentials live in the
.env
file
-
A branch is created for each ticket from the dev branch
-
Example of Branch Name:
- feature/{ticket_number}
- bugfix/{ticket_number}
- hotfix/{ticket_number}
- dev
- staging
- master
-
Read the next section for more information
๐ฆnodejs-typescript-federated-graphql-boilerplate
โฃ ๐.husky
โ โฃ ๐_
โ โ โฃ ๐.gitignore
โ โ โ ๐husky.sh
โ โฃ ๐commit-msg
โ โฃ ๐pre-commit
โ โ ๐pre-push
โฃ ๐src
โ โฃ ๐database-test
โ โ โฃ ๐Dockerfile
โ โ โ ๐sockets.seed.data
โ โฃ ๐gateway
โ โ โฃ ๐src
โ โ โ โฃ ๐test
โ โ โ โ โ ๐unit
โ โ โ โ โ โ ๐util
โ โ โ โ โ โ โ ๐logger.unit.test.ts
โ โ โ โฃ ๐util
โ โ โ โ โฃ ๐index.ts
โ โ โ โ โ ๐logger.ts
โ โ โ โ ๐index.ts
โ โ โฃ ๐.nvmrc
โ โ โฃ ๐Dockerfile
โ โ โฃ ๐newrelic.js
โ โ โฃ ๐package.json
โ โ โ ๐tsconfig.json
โ โ ๐subgraphs
โ โ โ ๐socket
โ โ โ โฃ ๐src
โ โ โ โ โฃ ๐app
โ โ โ โ โ โฃ ๐mongo-server
โ โ โ โ โ โ โ ๐index.ts
โ โ โ โ โ โฃ ๐node-server
โ โ โ โ โ โ โฃ ๐index.ts
โ โ โ โ โ โ โ ๐schema.graphql
โ โ โ โ โ โ ๐index.ts
โ โ โ โ โฃ ๐config
โ โ โ โ โ โฃ ๐countries.json
โ โ โ โ โ โฃ ๐cow.txt
โ โ โ โ โ โฃ ๐index.ts
โ โ โ โ โ โ ๐mongo-config.ts
โ โ โ โ โฃ ๐cron
โ โ โ โ โ โฃ ๐index.ts
โ โ โ โ โ โ ๐pullSocket.ts
โ โ โ โ โฃ ๐middleware
โ โ โ โ โฃ ๐model
โ โ โ โ โ โฃ ๐index.ts
โ โ โ โ โ โ ๐socket.ts
โ โ โ โ โฃ ๐resolver
โ โ โ โ โ โฃ ๐query
โ โ โ โ โ โ โฃ ๐index.ts
โ โ โ โ โ โ โฃ ๐socket.ts
โ โ โ โ โ โ โ ๐sockets.ts
โ โ โ โ โ โ ๐index.ts
โ โ โ โ โฃ ๐test
โ โ โ โ โ โฃ ๐e2e
โ โ โ โ โ โ โ ๐resolver
โ โ โ โ โ โ โ โ ๐query
โ โ โ โ โ โ โ โ โฃ ๐socket.e2e.test.ts
โ โ โ โ โ โ โ โ โ ๐sockets.e2e.test.ts
โ โ โ โ โ โ ๐unit
โ โ โ โ โ โ โ ๐util
โ โ โ โ โ โ โ โฃ ๐array.unit.test.ts
โ โ โ โ โ โ โ โฃ ๐enum.unit.test.ts
โ โ โ โ โ โ โ โฃ ๐generateCountriesJson.unit.test.ts
โ โ โ โ โ โ โ โฃ ๐generateSubBoundingBoxesOfCountry.unit.test.ts
โ โ โ โ โ โ โ โ ๐logger.unit.test.ts
โ โ โ โ โฃ ๐type
โ โ โ โ โ โฃ ๐config
โ โ โ โ โ โ โฃ ๐country.ts
โ โ โ โ โ โ โ ๐index.ts
โ โ โ โ โ โฃ ๐model
โ โ โ โ โ โ โฃ ๐index.ts
โ โ โ โ โ โ โ ๐socket.ts
โ โ โ โ โ โฃ ๐resolver
โ โ โ โ โ โ โฃ ๐query
โ โ โ โ โ โ โ โฃ ๐index.ts
โ โ โ โ โ โ โ โ ๐sockets.ts
โ โ โ โ โ โ โ ๐index.ts
โ โ โ โ โ โ ๐index.ts
โ โ โ โ โฃ ๐util
โ โ โ โ โ โฃ ๐array.ts
โ โ โ โ โ โฃ ๐enum.ts
โ โ โ โ โ โฃ ๐generateCountriesJson.ts
โ โ โ โ โ โฃ ๐generateSubBoundingBoxesOfCountry.ts
โ โ โ โ โ โฃ ๐index.ts
โ โ โ โ โ โ ๐logger.ts
โ โ โ โ โ ๐index.ts
โ โ โ โฃ ๐.nvmrc
โ โ โ โฃ ๐Dockerfile
โ โ โ โฃ ๐newrelic.js
โ โ โ โฃ ๐package.json
โ โ โ โ ๐tsconfig.json
โฃ ๐.commitlintrc.json
โฃ ๐.dockerignore
โฃ ๐.env
โฃ ๐.env.sample
โฃ ๐.env.test
โฃ ๐.eslintrc.json
โฃ ๐.gitignore
โฃ ๐.nvmrc
โฃ ๐.prettierrc.json
โฃ ๐LICENSE
โฃ ๐PROBLEM.md
โฃ ๐README.md
โฃ ๐SOLUTION.md
โฃ ๐docker-compose.sample.yml
โฃ ๐docker-compose.test.yml
โฃ ๐docker-compose.yml
โฃ ๐jest.config.js
โฃ ๐package-lock.json
โฃ ๐package.json
โ ๐tsconfig.json
-
- The Open Charge Map API provides access to the world's largest registry of charging locations as Open Data.
-
-
The solution involves conceptualizing each country as a small rectangle, encompassing all of its borders, and representing each corner of the rectangle with coordinates.
-
The data for edge coordinates was obtained from here where I reached through this stack exchange answer.
-
- AGPL-3.0-or-later
Vishal Kumar - Software Engineer ๐จโ๐ป and an Aspiring Entrepreneur๐จโ๐ผ