Skip to content

Commit 6cbb9bc

Browse files
committed
Updated Flask SQLAlchemy example
1 parent bc6240d commit 6cbb9bc

File tree

3 files changed

+19
-7
lines changed

3 files changed

+19
-7
lines changed

examples/flask_sqlalchemy/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ whole Graphene repository:
1414
```bash
1515
# Get the example project code
1616
git clone https://github.com/graphql-python/graphene.git
17-
cd graphene/examples/cookbook
17+
cd graphene/examples/flask_sqlalchemy
1818
```
1919

2020
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:
4646

4747

4848
Now head on over to
49-
[http://127.0.0.1:5000/](http://127.0.0.1:5000/)
49+
[http://127.0.0.1:5000/graphiql](http://127.0.0.1:5000/graphiql)
5050
and run some queries!

examples/flask_sqlalchemy/app.py

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,27 @@
1-
import json
21
from flask import Flask
32
from database import db_session, init_db
43

54
from schema import schema, Department
5+
from graphql_flask import GraphQL
66

77
app = Flask(__name__)
8+
app.debug = True
89

10+
default_query = '''
11+
{
12+
node(id:"%s") {
13+
name
14+
employees {
15+
edges {
16+
node {
17+
name
18+
}
19+
}
20+
}
21+
}
22+
}'''.strip() % Department.global_id(1)
923

10-
@app.route('/')
11-
def hello_world():
12-
query = '{node(id:"%s"){name, employees { edges { node {name} } } } }' % Department.global_id(1)
13-
return json.dumps(schema.execute(query).data)
24+
GraphQL(app, schema=schema, default_query=default_query)
1425

1526

1627
@app.teardown_appcontext
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
graphene[sqlalchemy]
2+
graphql_flask==1.0.0
23
SQLAlchemy==1.0.11
34
Flask==0.10.1

0 commit comments

Comments
 (0)