diff options
| author | Christian Breunig <christian@breunig.cc> | 2023-03-04 05:37:33 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-03-04 05:37:33 +0100 |
| commit | 493af3f3417cef5c9898f242a2b885e63e3bdeef (patch) | |
| tree | b9536a832d7693f2f35d90fc75b58ff57be4d640 /src/services/api/graphql/generate/schema_from_config_session.py | |
| parent | e5eb4f332f03df51d64d51e7f38ee561f298188c (diff) | |
| parent | 7ab3b9e021e7ce1c56b9f252a04400a37fd33e71 (diff) | |
| download | veeos-1x-493af3f3417cef5c9898f242a2b885e63e3bdeef.tar.gz veeos-1x-493af3f3417cef5c9898f242a2b885e63e3bdeef.zip | |
Merge pull request #1862 from jestabro/schema-generate
graphql: T5040: generate schema on installation, rather than dynamically
Diffstat (limited to 'src/services/api/graphql/generate/schema_from_config_session.py')
| -rwxr-xr-x | src/services/api/graphql/generate/schema_from_config_session.py | 51 |
1 files changed, 4 insertions, 47 deletions
diff --git a/src/services/api/graphql/generate/schema_from_config_session.py b/src/services/api/graphql/generate/schema_from_config_session.py index 49bf2440e..831faa41e 100755 --- a/src/services/api/graphql/generate/schema_from_config_session.py +++ b/src/services/api/graphql/generate/schema_from_config_session.py @@ -26,12 +26,9 @@ from jinja2 import Template from vyos.defaults import directories if __package__ is None or __package__ == '': - sys.path.append("/usr/libexec/vyos/services/api") + sys.path.append(os.path.join(directories['services'], 'api')) from graphql.libs.op_mode import snake_to_pascal_case, map_type_name from config_session_function import queries, mutations - from vyos.config import Config - from vyos.configdict import dict_merge - from vyos.xml import defaults else: from .. libs.op_mode import snake_to_pascal_case, map_type_name from . config_session_function import queries, mutations @@ -39,40 +36,16 @@ else: SCHEMA_PATH = directories['api_schema'] -if __package__ is None or __package__ == '': - # allow running stand-alone - conf = Config() - base = ['service', 'https', 'api'] - graphql_dict = conf.get_config_dict(base, key_mangling=('-', '_'), - no_tag_node_value_mangle=True, - get_first_key=True) - if 'graphql' not in graphql_dict: - exit("graphql is not configured") - - graphql_dict = dict_merge(defaults(base), graphql_dict) - auth_type = graphql_dict['graphql']['authentication']['type'] -else: - auth_type = state.settings['app'].state.vyos_auth_type - -schema_data: dict = {'auth_type': auth_type, - 'schema_name': '', +schema_data: dict = {'schema_name': '', 'schema_fields': []} query_template = """ -{%- if auth_type == 'key' %} input {{ schema_name }}Input { - key: String! + key: String {%- for field_entry in schema_fields %} {{ field_entry }} {%- endfor %} } -{%- elif schema_fields %} -input {{ schema_name }}Input { - {%- for field_entry in schema_fields %} - {{ field_entry }} - {%- endfor %} -} -{%- endif %} type {{ schema_name }} { result: Generic @@ -85,29 +58,17 @@ type {{ schema_name }}Result { } extend type Query { -{%- if auth_type == 'key' or schema_fields %} {{ schema_name }}(data: {{ schema_name }}Input) : {{ schema_name }}Result @configsessionquery -{%- else %} - {{ schema_name }} : {{ schema_name }}Result @configsessionquery -{%- endif %} } """ mutation_template = """ -{%- if auth_type == 'key' %} -input {{ schema_name }}Input { - key: String! - {%- for field_entry in schema_fields %} - {{ field_entry }} - {%- endfor %} -} -{%- elif schema_fields %} input {{ schema_name }}Input { + key: String {%- for field_entry in schema_fields %} {{ field_entry }} {%- endfor %} } -{%- endif %} type {{ schema_name }} { result: Generic @@ -120,11 +81,7 @@ type {{ schema_name }}Result { } extend type Mutation { -{%- if auth_type == 'key' or schema_fields %} {{ schema_name }}(data: {{ schema_name }}Input) : {{ schema_name }}Result @configsessionmutation -{%- else %} - {{ schema_name }} : {{ schema_name }}Result @configsessionmutation -{%- endif %} } """ |
