community/boilerplates/remote-schemas/zeit-now/python/flask-graphene-sqlalchemy/README.md
A boilerplate Python GraphQL Server using Flask and Graphene.
Python 2.7
Postgres
Zeit
Flask (Web framework)
Graphene (GraphQL framework)
SqlAlchemy (Postgres ORM)
The sample source code is present in server.py. Clone the repo and go to community/boilerplates/remote-schemas/zeit-now/python/flask-graphene-sqlalchemy folder:
$ git clone [email protected]:hasura/graphql-engine
$ cd graphql-engine/community/boilerplates/remote-schemas/zeit-now/python/flask-graphene-sqlalchemy
$ export POSTGRES_CONNECTION_STRING='postgres://username:[email protected]:5432/mydb'
psql $POSTGRES_CONNECTION_STRING -c "create table users(id serial primary key, name text, balance integer); create table min_amount(amount integer); insert into min_amount values (100)"
pip install -r requirements.txt
export FLASK_APP=server.py
flask run
Running the server using Docker:
docker build -t python-flask-graphene .
docker run -p 5000:5000 python-flask-graphene
This will start a local server on localhost:5000. You can hit the graphql service at localhost:5000/graphql which opens GraphiQL.
Install the Zeit Now CLI:
npm install -g now
Deploy the server:
now
Get the URL and make a sample query:
curl https://python-flask-graphene-vynveodwau.now.sh/graphql \
-H 'Content-Type:application/json' \
-d'{"query":"{ hello }"}'
{"data":{"hello":"World"}}
You can also visit the now url to open GraphiQL.