Skip to content

Commit 60ba59b

Browse files
committed
Fixed tutorial with latest flask graphql package
1 parent 2f43a15 commit 60ba59b

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

pages/docs/sqlalchemy/tutorial.md

+11-5
Original file line numberDiff line numberDiff line change
@@ -119,23 +119,29 @@ schema.query = Query
119119

120120
Unlike a RESTful API, there is only a single URL from which GraphQL is accessed.
121121

122-
We are going to use Flask to create a server that expose the GraphQL schema under `/graphql` and a interface for querying it easily: GraphiQL under `/graphiql`.
122+
We are going to use Flask to create a server that expose the GraphQL schema under `/graphql` and a interface for querying it easily: GraphiQL (also under `/graphql` when accessed by a browser).
123123

124124
Fortunately for us, the library `Flask-GraphQL` that we previously installed makes this task quite easy.
125125

126126
```python
127127
# flask_sqlalchemy/app.py
128128
from flask import Flask
129-
from flask_graphql import GraphQL
129+
from flask_graphql import GraphQLView
130130

131131
from models import db_session
132132
from schema import schema, Department
133133

134134
app = Flask(__name__)
135135
app.debug = True
136136

137-
# This is creating the `/graphql` and `/graphiql` endpoints
138-
GraphQL(app, schema=schema)
137+
app.add_url_rule(
138+
'/graphql',
139+
view_func=GraphQLView.as_view(
140+
'graphql',
141+
schema=schema,
142+
graphiql=True # for having the GraphiQL interface
143+
)
144+
)
139145

140146
@app.teardown_appcontext
141147
def shutdown_session(exception=None):
@@ -180,7 +186,7 @@ $ python ./app.py
180186
* Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
181187
```
182188

183-
Go to [localhost:5000/graphiql](http://localhost:5000/graphiql) and type your first query!
189+
Go to [localhost:5000/graphql](http://localhost:5000/graphql) and type your first query!
184190

185191
```graphql
186192
{

0 commit comments

Comments
 (0)