Skip to content

Instantly share code, notes, and snippets.

@birk-astrup
Last active November 1, 2019 14:04
Show Gist options
  • Save birk-astrup/ec5802a97ea13365328da3119e32f2f4 to your computer and use it in GitHub Desktop.
Save birk-astrup/ec5802a97ea13365328da3119e32f2f4 to your computer and use it in GitHub Desktop.
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