-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnshm_model_graphql_api.py
65 lines (49 loc) · 1.59 KB
/
nshm_model_graphql_api.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
"""Main module."""
import logging
import logging.config
import os
import yaml
from flask import Flask
from flask_cors import CORS
from flask_graphql import GraphQLView
# from nshm_model_graphql_api.library_version_check import log_library_info
from nshm_model_graphql_api.schema import schema_root
LOGGING_CFG = os.getenv("LOGGING_CFG", "nshm_model_graphql_api/logging_aws.yaml")
logger = logging.getLogger(__name__)
# TESTING = os.getenv('TESTING', False)
# if not TESTING:
# # because in testing, this screws up moto mocking
# log_library_info(['botocore', 'boto3', 'fiona'])
def create_app():
"""Function that creates our Flask application."""
app = Flask(__name__)
CORS(app)
# app.before_first_request(migrate)
app.add_url_rule(
"/graphql",
view_func=GraphQLView.as_view(
"graphql",
schema=schema_root,
graphiql=True,
),
)
"""
Setup logging configuration
ref https://fangpenlin.com/posts/2012/08/26/good-logging-practice-in-python/
"""
if os.path.exists(LOGGING_CFG):
with open(LOGGING_CFG, "rt") as f:
config = yaml.safe_load(f.read())
logging.config.dictConfig(config)
else:
print("Warning, no logging config found, using basicConfig(INFO)")
logging.basicConfig(level=logging.INFO)
logger.debug("DEBUG logging enabled")
logger.info("INFO logging enabled")
logger.warning("WARN logging enabled")
logger.error("ERROR logging enabled")
return app
# pragma: no cover
app = create_app()
if __name__ == "__main__":
app.run()