You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: pages/docs/sqlalchemy/tutorial.md
+11-5
Original file line number
Diff line number
Diff line change
@@ -119,23 +119,29 @@ schema.query = Query
119
119
120
120
Unlike a RESTful API, there is only a single URL from which GraphQL is accessed.
121
121
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).
123
123
124
124
Fortunately for us, the library `Flask-GraphQL` that we previously installed makes this task quite easy.
125
125
126
126
```python
127
127
# flask_sqlalchemy/app.py
128
128
from flask import Flask
129
-
from flask_graphql importGraphQL
129
+
from flask_graphql importGraphQLView
130
130
131
131
from models import db_session
132
132
from schema import schema, Department
133
133
134
134
app = Flask(__name__)
135
135
app.debug =True
136
136
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
+
)
139
145
140
146
@app.teardown_appcontext
141
147
defshutdown_session(exception=None):
@@ -180,7 +186,7 @@ $ python ./app.py
180
186
* Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
181
187
```
182
188
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!
0 commit comments