/Flask-GraphQL-API-PostgreSQL

Practice making a GraphQL API using Graphene, Flask, and PostGreSQL

Primary LanguagePython

Goal: Create a GraphQL API using graphene and flask. Graphene allows for a code first appoach. (Ariadne would use a schema first approach). SQLalchemy is an ORM.

Some References: https://www.youtube.com/watch?v=sUw2omk61Gg #Uses sqlite not PostgreSQL

PostgreSQL https://www.w3resource.com/PostgreSQL/postgresql-python-connection.php https://www.postgresqltutorial.com/postgresql-python/connect/ postgresql://[user[:password]@][netloc][:port][/dbname]

SQLAlchemy https://docs.sqlalchemy.org/en/14/dialects/postgresql.html https://www.compose.com/articles/using-postgresql-through-sqlalchemy/ https://docs.graphene-python.org/projects/sqlalchemy/en/latest/tutorial/#setup-the-project

Graphene https://graphene-python.org/

Flask https://flask.palletsprojects.com/en/2.1.x/quickstart/

Process:

create virtual environment in gitbash:

* python -m venv env
* source env/Scripts/activate
* pip install graphene graphene-sqlalchemy flask sqlalchemy Flask-GraphQL (note: there was initial difficulty as the dependencies are specific ex: requires >1.1 <2)
* pip freeze > requirements.txt


* create table in db/\_\_init__.py  with classes and use SQLalchemy
* connection.py (in .gitignore is has connection string)
* run create_db.py to create db
* add objects into db: scripts.py
* define schema (schemas/\_\_init__.py) based off of data via graphene
* create Query (schemas/\_\_init__.py)
* create Mutations (schemas/\_\_init__.py)

* add connnection.py to .gitignore

Terminal/GitBash:

* export FLASK_APP=main.py
* export FLASK_DEBUG=1
* flask run