This project is part of the article I wrote for ThePythonCode.com.
You can check out the article using this link:
It is a tutorial on how to build a GraphQL API in Python using FastAPI (for route handling), Strawberry (for Schema definition and everything GraphQL), and Postgres (the database).
If you decided to follow along the tutorial (or just to run this project), first, make sure you have:
- ElephantSQL Account (optional) - If you decided to use Postgres (like in the tutorial) and decided to go for the managed Postgres DB option
- Python3: ^3.11.0
-
Fork this repo.
-
Clone it in your local device.
git clone git@github.com:<user>/PythonGQLArticle.git cd PythonGQLArticle
-
Create a virtual environment
python3 -m venv pygql
-
Activate the virtual environment
# MacOS/Linux source pygql/bin/activate # Windows pygql\Scripts\activate
-
Install the dependencies
pip3 install -r requirements.txt
-
Add your Database URL - Create a
.env
file, add your DATABASE URL, and access it in thedatabase.py
file:# .env file DB_URL='<YOUR DATABASE URL HERE>'
# models/database.py ... SQLALCHEMY_DATABASE_URL = config("DB_URL")
-
Run the server
uvicorn main:app --reload
-
Open http://localhost:8000/graphql in your browser.