FastAPI + GraphQL Starter
A python starter project using FastAPI and GraphQL. This project leverages docker for containerization and provides the scripts to deploy to Heroku. The starter is created for and used in the Building Python Apps with FastAPI book by Eidan J. Rosado.
Running Services with Docker
To avoid setting up MongoDB and other such services locally, the team uses Docker. You’ll need to install Docker to proceed pulling the image from the team’s hub. Contact one of the team admins for access to the hub. To start peripheral services simply execute the following:
To refresh the image on your local (for server devs), run the following:
docker build -t fastapistarter -f Dockerfile.web .
You can run the one off image and container with the following:
docker run -d --name fastapistarter -p 8000:8000 -p 8001:8001 fastapistarter
If you are pushing to your personal stack on Heroku, you’ll need to run the dockerization steps above to build the base image and then follow up with the Heroku containerization steps below.
heroku container:push –recursive
heroku container:release web
Note: You must do a heroku login or use API tokens to push to the container registry
Running API Locally
You’ll need the following environment variables configured or in a .env file to run the server successfully:
# FastAPI Setup export HOST="127.0.0.1" export PORT=8000 export WEBHOOKS_PORT=8001 # fastapistarter DB Setup export DB_URL='mongodb://localhost:27017' export DB_NAME='fastapistarter'
The main entry point is main.py, so you can start that file from command line or use whatever execution method is available from your IDE. To install the IDE to interact with GraphQL, look in the SETUP.md for GraphQL Playground installation instructions then simply open the GraphQL Playground to interact with the local server and insert the base url http://127.0.0.1:8000/graph. For more detailed instructions, check the wiki.
Changes under /app may be picked up by the auto-refresh (no need to restart server). To understand how to use the playground to run queries, please reference the following: GraphQL Queries Reference
All tests are located under the tests folder. To run them from terminal, execute the following: