-
Notifications
You must be signed in to change notification settings - Fork 227
/
Copy pathapi.py
41 lines (34 loc) · 916 Bytes
/
api.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# coding=utf-8
import sqlalchemy.orm
import falcon
import graphene
from demo.resources import ResourceGraphQlSqlAlchemy
from demo.resources import ResourceGraphiQL
def create_app(
schema: graphene.Schema,
scoped_session: sqlalchemy.orm.scoped_session,
do_enable_graphiql: bool,
):
# Create the API.
app = falcon.API()
app.add_route(
uri_template="/graphql",
resource=ResourceGraphQlSqlAlchemy(
schema=schema,
scoped_session=scoped_session,
)
)
if do_enable_graphiql:
app.add_route(
uri_template="/graphiql/",
resource=ResourceGraphiQL(
path_graphiql="graphiql",
)
)
app.add_route(
uri_template="/graphiql/{static_file}",
resource=ResourceGraphiQL(
path_graphiql="graphiql",
)
)
return app