Last active
November 1, 2019 14:04
-
-
Save birk-astrup/ec5802a97ea13365328da3119e32f2f4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from ariadne import graphql_sync, make_executable_schema, load_schema_from_path, ObjectType, QueryType | |
from ariadne.constants import PLAYGROUND_HTML | |
from flask import Flask, request, jsonify | |
app = Flask(__name__) | |
@app.route('/graphql', methods=['GET']) | |
def playground(): | |
return PLAYGROUND_HTML, 200 | |
@app.route('/graphql', methods=['POST']) | |
def graphql_server(): | |
data = request.get_json() | |
success, result = graphql_sync( | |
schema, | |
data, | |
context_value=None, | |
debug=app.debug | |
) | |
status_code = 200 if success else 400 | |
return jsonify(result), status_code |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment