项目作者: timfeirg

项目描述 :
Flask GraphQL example app
高级语言: Python
项目地址: git://github.com/timfeirg/flask-graphene-boilerplate.git
创建时间: 2018-04-06T12:38:29Z
项目社区:https://github.com/timfeirg/flask-graphene-boilerplate

开源协议:MIT License

下载


As a child, I always dreamed of writing solely CRUD operations and HTTP APIs will just be magically available, now I can finally achieve this with graphql.

This project demonstrates how to use Flask + Flask-GraphQL to make a simple web app with simple CRUD operations, also includes some of the most basic tests.

Setup everything and run the flask app

On a Mac of course.

  1. brew install python3
  2. pip install -U virtualenv virtualenvwrapper
  3. mkvirtualenv graphene --python=python3
  4. pip install -U -r requirements-dev.txt
  5. mysql -uroot -e 'create database graphene_boilerplate'
  6. py.test -s
  7. ./shell
  8. > db.create_all()
  9. > exit
  10. export FLASK_APP=graphene_boilerplate/app.py
  11. flask run --reload --port 5000

Now open up http://localhost:5000/graphql to play with GraphQL, see below for some example queries:

To create a Item:

  1. mutation see_if_create_works {
  2. createItem(key: "whatever", value: "{\"foo\": \"bar\"}") {
  3. ok
  4. item {
  5. id_
  6. key
  7. value
  8. }
  9. }
  10. }

To list all Item:

  1. query {
  2. allItems {
  3. edges {
  4. node {
  5. id_
  6. key
  7. value
  8. }
  9. }
  10. }
  11. }