mirror of
https://github.com/graphql-python/graphene.git
synced 2024-11-22 17:46:57 +03:00
Updated Flask SQLAlchemy example
This commit is contained in:
parent
bc6240d378
commit
6cbb9bc602
|
@ -14,7 +14,7 @@ whole Graphene repository:
|
|||
```bash
|
||||
# Get the example project code
|
||||
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
|
||||
|
@ -46,5 +46,5 @@ Now the following command will setup the database, and start the server:
|
|||
|
||||
|
||||
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!
|
||||
|
|
|
@ -1,16 +1,27 @@
|
|||
import json
|
||||
from flask import Flask
|
||||
from database import db_session, init_db
|
||||
|
||||
from schema import schema, Department
|
||||
from graphql_flask import GraphQL
|
||||
|
||||
app = Flask(__name__)
|
||||
app.debug = True
|
||||
|
||||
default_query = '''
|
||||
{
|
||||
node(id:"%s") {
|
||||
name
|
||||
employees {
|
||||
edges {
|
||||
node {
|
||||
name
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}'''.strip() % Department.global_id(1)
|
||||
|
||||
@app.route('/')
|
||||
def hello_world():
|
||||
query = '{node(id:"%s"){name, employees { edges { node {name} } } } }' % Department.global_id(1)
|
||||
return json.dumps(schema.execute(query).data)
|
||||
GraphQL(app, schema=schema, default_query=default_query)
|
||||
|
||||
|
||||
@app.teardown_appcontext
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
graphene[sqlalchemy]
|
||||
graphql_flask==1.0.0
|
||||
SQLAlchemy==1.0.11
|
||||
Flask==0.10.1
|
||||
|
|
Loading…
Reference in New Issue
Block a user