PopulationX is a simple and easy-to-use Population Management API built with GraphQL. The system provides information about various locations such as the total number of residents in each location broken down by gender, and the sum total of residents in a location.
The API enables users to:
-
Create a new location containing data on the total number of male and female residents within it (locations can be nested within other locations).
-
List all available locations and their population summaries (total male residents, total female residents, sum total residents). The parent location and child (nested) locations for each location can also be viewed in addition to the summaries.
-
Update data for a specific location
-
Delete a specified location.
For this application authentication is required for creating, deleting and updating a location.
- graphql-yoga: which is based on the following libraries and tools:
- apollo-server
- subscriptions-transport-ws (graphql Subscriptions)
- graphql-tools
- graphql-playground
- Prisma
- Node
- validatorjs
The following needs to be installed on your system to setup up the application:
The following steps can be taken to setup this application locally
git clone https://github.com/JCanaks/PopulationX.git
cd populationx
Run the following command to create an env file using the example env file provided
cp .env.example .env
You can now update the values for env variables used in the application
npm install
npm install -g prisma
Prisma powers the database layer of the application and connects to the GraphQL Server via the Prisma Client.
In this application Prisma is deployed locally using a Postgres database (Note: You would need Docker installed in order to set this up. See docker-compose.yml
file at the root of this project).
To achieve this, run the following command below to start up Prisma and launch the connected database according to the specifications in the docker-compose.yml
file at the root of this project.
docker-compose up -d
Once that is completed, deploy the prisma datamodel by running the following command:
prisma deploy
Prisma is now connected to a local database and runs on http://localhost:4477
You can use the Prisma Admin to view and edit the data in your database. To access the Prisma Admin use the following url -- http://localhost:4477/_admin
For more details on setting up Prisma locally please click here to view setup details in the Prisma Docs
Note: Prisma can also be deployed using a free demo database that is hosted in Prisma Cloud. Click here to learn more about deploying Prisma using Prisma Cloud.
Run the following command to start the GraphQL server:
npm start
Navigate to http://localhost:4000
to test the GraphQL API with the GraphQL playground and you are good to go 🎉🎉.
To run tests locally ensure that the prisma server is started by running the command:
docker-compose up -d
After that, run the command below to run tests and view coverage report
npm test
The GraphQL Playground is a powerful GraphQl IDE that helps you work interactively with the GraphQL API. One of its cool features is the documentation explorer which enables you visualize the structure of the GraphQL schema. This self documenting GraphQL feature enables you to easily understand the schema structure of the application and the structure of the data to be returned when writing GraphQL queries. This documentation can be accessed by clicking on the DOCS
tab on the right side of the playground
The schema of the application can also be viewed by clicking on the SCHEMA
tab on the right side of the playground
- Jane C. Anaekwe - @JCanaks