-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathapp.py
38 lines (34 loc) · 847 Bytes
/
app.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
from sanic_graphql import GraphQLView
from sanic import Sanic
from database import db_session, init_db
from schema import schema
app = Sanic(__name__)
app.debug = True
# This will be the query
default_query = """
{
allEmployee {
edges {
node {
id,
name,
department {
id,
name
},
role {
id,
name
}
}
}
}
}
""".strip()
# It's like HTTP routes but instead, it directs you to /graphql (Schema).
# graphiq = True will initiate the GUI
app.add_route(GraphQLView.as_view(schema=schema, graphiql=True), '/graphql')
# runs the app and database. init_db contains seed data.
if __name__ == '__main__':
init_db()
app.run()