graphene/graphene-sqlalchemy/examples/flask_sqlalchemy/app.py

41 lines
655 B
Python
Raw Normal View History

2016-01-23 08:44:41 +03:00
from flask import Flask
from database import db_session, init_db
2016-07-23 06:32:18 +03:00
from flask_graphql import GraphQLView
from schema import schema
2016-01-23 08:44:41 +03:00
app = Flask(__name__)
2016-01-23 22:00:00 +03:00
app.debug = True
2016-01-23 08:44:41 +03:00
2016-01-23 22:00:00 +03:00
default_query = '''
{
2016-01-24 00:14:10 +03:00
allEmployees {
edges {
node {
2016-04-13 15:16:01 +03:00
id,
name,
2016-01-24 00:14:10 +03:00
department {
2016-04-13 15:16:01 +03:00
id,
name
},
role {
id,
2016-01-23 22:00:00 +03:00
name
}
}
}
2016-04-13 15:41:04 +03:00
}
2016-01-24 00:14:10 +03:00
}'''.strip()
2016-01-23 08:44:41 +03:00
2016-07-23 06:32:18 +03:00
app.add_url_rule('/graphql', view_func=GraphQLView.as_view('graphql', schema=schema, graphiql=True))
2016-01-23 08:44:41 +03:00
@app.teardown_appcontext
def shutdown_session(exception=None):
db_session.remove()
if __name__ == '__main__':
init_db()
app.run()