-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
46 lines (34 loc) · 1.53 KB
/
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
39
40
41
42
43
44
45
46
from api import app, db
from ariadne import load_schema_from_path, make_executable_schema, \
graphql_sync, snake_case_fallback_resolvers, ObjectType
from ariadne.constants import PLAYGROUND_HTML
from flask import request, jsonify
from api.queries import listTeams_resolver,getTeam_ByName_resolver,listRegions_resolver,listPlayers_resolver,getPlayer_ByName_resolver,getTeam_ByRegion_resolver,getPlayer_ByPseudo_resolver,listTransfert_resolver,listMatches_resolver
query = ObjectType("Query")
query.set_field("listAllTeams", listTeams_resolver)
query.set_field("getTeam_ByName", getTeam_ByName_resolver)
query.set_field("getTeam_ByRegion", getTeam_ByRegion_resolver)
query.set_field("listAllRegions", listRegions_resolver)
query.set_field("listAllPlayers", listPlayers_resolver)
query.set_field("getPlayer_ByName", getPlayer_ByName_resolver)
query.set_field("getPlayer_ByPseudo", getPlayer_ByPseudo_resolver)
query.set_field("listAlltransferts", listTransfert_resolver)
query.set_field("listAllMatches", listMatches_resolver)
type_defs = load_schema_from_path("schema.graphql")
schema = make_executable_schema(
type_defs, query, snake_case_fallback_resolvers
)
@app.route("/", methods=["GET"])
def graphql_playground():
return PLAYGROUND_HTML, 200
@app.route("/", methods=["POST"])
def graphql_server():
data = request.get_json()
success, result = graphql_sync(
schema,
data,
context_value=request,
debug=app.debug
)
status_code = 200 if success else 400
return jsonify(result), status_code