mirror of
https://github.com/graphql-python/graphene.git
synced 2024-11-26 11:33:55 +03:00
Updated Flask SQLAlchemy example
This commit is contained in:
parent
bc6240d378
commit
6cbb9bc602
|
@ -14,7 +14,7 @@ whole Graphene repository:
|
||||||
```bash
|
```bash
|
||||||
# Get the example project code
|
# Get the example project code
|
||||||
git clone https://github.com/graphql-python/graphene.git
|
git clone https://github.com/graphql-python/graphene.git
|
||||||
cd graphene/examples/cookbook
|
cd graphene/examples/flask_sqlalchemy
|
||||||
```
|
```
|
||||||
|
|
||||||
It is good idea (but not required) to create a virtual environment
|
It is good idea (but not required) to create a virtual environment
|
||||||
|
@ -46,5 +46,5 @@ Now the following command will setup the database, and start the server:
|
||||||
|
|
||||||
|
|
||||||
Now head on over to
|
Now head on over to
|
||||||
[http://127.0.0.1:5000/](http://127.0.0.1:5000/)
|
[http://127.0.0.1:5000/graphiql](http://127.0.0.1:5000/graphiql)
|
||||||
and run some queries!
|
and run some queries!
|
||||||
|
|
|
@ -1,16 +1,27 @@
|
||||||
import json
|
|
||||||
from flask import Flask
|
from flask import Flask
|
||||||
from database import db_session, init_db
|
from database import db_session, init_db
|
||||||
|
|
||||||
from schema import schema, Department
|
from schema import schema, Department
|
||||||
|
from graphql_flask import GraphQL
|
||||||
|
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
|
app.debug = True
|
||||||
|
|
||||||
|
default_query = '''
|
||||||
|
{
|
||||||
|
node(id:"%s") {
|
||||||
|
name
|
||||||
|
employees {
|
||||||
|
edges {
|
||||||
|
node {
|
||||||
|
name
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}'''.strip() % Department.global_id(1)
|
||||||
|
|
||||||
@app.route('/')
|
GraphQL(app, schema=schema, default_query=default_query)
|
||||||
def hello_world():
|
|
||||||
query = '{node(id:"%s"){name, employees { edges { node {name} } } } }' % Department.global_id(1)
|
|
||||||
return json.dumps(schema.execute(query).data)
|
|
||||||
|
|
||||||
|
|
||||||
@app.teardown_appcontext
|
@app.teardown_appcontext
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
graphene[sqlalchemy]
|
graphene[sqlalchemy]
|
||||||
|
graphql_flask==1.0.0
|
||||||
SQLAlchemy==1.0.11
|
SQLAlchemy==1.0.11
|
||||||
Flask==0.10.1
|
Flask==0.10.1
|
||||||
|
|
Loading…
Reference in New Issue
Block a user