The idea behind this project is to demonstrate using GraphQL how we can query large sets of datasets by combining different sets of API endpoints? and GraphQL is a very popular data query and manipulation language developed by Facebook and using GraphQL we can populate large sets of data using a single query in a very faster and efficient way. To demonstrate the proof of concept I have taken the datasets from COVID-19 project and those datasets used for analysis in this project.
The proof of concept written using python and to implement the GraphQL it uses graphene python module and the microservices designed and implemented using flask framework and to store the data it uses mongodb database for the storage.
There are three different types of microservices designed in this project
- Statistics
- Total Cases
- Subscriptions
git clone https://github.com/anshumanpattnaik/python-graphql-microservices
cd python-graphql-microservices
pip install -r requirements.txt
source venv/bin/activate
python3 run.py
Under covid19_dummy_data/
folder you will find the statistics data.json file, which you can use while adding data using http://127.0.0.1:5000/api/v1/add_statistics
endpoint.
After the installation and importing the data into mongodb database, you can open http://127.0.0.1:5000/api/v1/graphql
to view in the browser.
To refer the queries you can follow graphql_queries/
folder for all_queries.graphql and mutation_query.graphql which you can use to analyze the data.
Using all queries it will populate three different sets of data.
- Statistics of all counties - (allStatistics)
- Total Cases around the world - (allTotalCases)
- List of COVID-19 email subscribers - (allSubscriber)
{
allStatistics {
edges {
node {
code
country
flag
coordinates
confirmed
deaths
recovered
states {
edges {
node {
name
address
latitude
longitude
confirmed
deaths
recovered
}
}
}
}
}
},
allTotalCases {
edges {
node {
totalConfirmed
totalDeaths
totalRecovered
}
}
},
allSubscriber {
edges {
node {
email
}
}
}
}
Using mutation query you can populate the statistics of the individual country by passing the country name.
mutation {
fetchByCountryName(country: "India") {
statistics {
code
country
flag
coordinates
confirmed
deaths
recovered
states {
edges {
node {
name
address
latitude
longitude
confirmed
deaths
recovered
}
}
}
}
}
}
To understand more in-depth I'll highly recommend following the official documentation of GraphQL and Graphene
This project is licensed under the MIT License