-
Notifications
You must be signed in to change notification settings - Fork 112
/
api.py
37 lines (28 loc) · 1.09 KB
/
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
import json
import falcon
from .schema import schema
def set_graphql_allow_header(req: falcon.Request, resp: falcon.Response, resource: object):
resp.set_header("Allow", "GET, POST, OPTIONS")
class HelloWorldResource:
def on_get(self, req, resp):
name = "Hello World!"
resp.status = falcon.HTTP_200
resp.body = json.dumps({"respone": name, "status": resp.status})
def on_post(self, req, resp):
pass
@falcon.after(set_graphql_allow_header)
class GraphQLResource:
def on_get(self, req, resp):
query = req.params["query"]
result = await schema.execute_async(query)
if result.data:
data_ret = {"data": result.data}
resp.status = falcon.HTTP_200
resp.body = json.dumps(data_ret, separators=(",", ":"))
def on_post(self, req, resp):
query = req.params["query"]
result = await schema.execute_async(query)
if result.data:
data_ret = {"data": result.data}
resp.status = falcon.HTTP_200
resp.body = json.dumps(data_ret, separators=(",", ":"))