Changeset View
Changeset View
Standalone View
Standalone View
swh/graphql/server.py
Show First 20 Lines • Show All 56 Lines • ▼ Show 20 Lines | |||||
def make_app_from_configfile(): | def make_app_from_configfile(): | ||||
"""Loading the configuration from a configuration file. | """Loading the configuration from a configuration file. | ||||
SWH_CONFIG_FILENAME environment variable defines the | SWH_CONFIG_FILENAME environment variable defines the | ||||
configuration path to load. | configuration path to load. | ||||
""" | """ | ||||
from .app import schema | from .app import schema, validation_rules | ||||
global graphql_cfg | global graphql_cfg | ||||
if not graphql_cfg: | if not graphql_cfg: | ||||
config_path = os.environ.get("SWH_CONFIG_FILENAME") | config_path = os.environ.get("SWH_CONFIG_FILENAME") | ||||
graphql_cfg = load_and_check_config(config_path) | graphql_cfg = load_and_check_config(config_path) | ||||
server_type = graphql_cfg.get("server-type") | server_type = graphql_cfg.get("server-type") | ||||
if server_type == "asgi": | if server_type == "asgi": | ||||
from ariadne.asgi import GraphQL | from ariadne.asgi import GraphQL | ||||
from starlette.middleware.cors import CORSMiddleware | from starlette.middleware.cors import CORSMiddleware | ||||
# Enable cors in the asgi version | # Enable cors in the asgi version | ||||
application = CORSMiddleware( | application = CORSMiddleware( | ||||
GraphQL(schema), | GraphQL(schema, validation_rules=validation_rules), | ||||
allow_origins=["*"], | allow_origins=["*"], | ||||
allow_methods=("GET", "POST", "OPTIONS"), | allow_methods=("GET", "POST", "OPTIONS"), | ||||
) | ) | ||||
else: | else: | ||||
from ariadne.wsgi import GraphQL | from ariadne.wsgi import GraphQL | ||||
application = GraphQL(schema) | application = GraphQL(schema, validation_rules=validation_rules) | ||||
return application | return application |