-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.py
26 lines (22 loc) · 866 Bytes
/
server.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
from flask import Flask, request, jsonify
from ariadne import make_executable_schema, gql, load_schema_from_path, graphql_sync
from ariadne.explorer import ExplorerPlayground
from model import query
PLAYGROUND_HTML = ExplorerPlayground(title="API").html(None)
type_defs = gql(load_schema_from_path("./schema.graphql"))
schema = make_executable_schema(type_defs, query)
app = Flask(__name__)
@app.route('/')
def home():
return 'welcome to main; status: 200'
@app.route('/graphql', methods=["GET"])
def gql_interface():
return PLAYGROUND_HTML,200
@app.route('/graphql', methods=["POST"])
def get_gql_api():
data = request.get_json()
success, result = graphql_sync(schema, data, context_value=request, debug=app.debug)
staus_code = 200 if success else 400
return jsonify(result), staus_code
if __name__ == "__main__":
app.run(debug=True)