summaryrefslogtreecommitdiff
path: root/src/services/api/graphql/generate/schema_from_composite.py
diff options
context:
space:
mode:
authorJohn Estabrook <jestabro@vyos.io>2023-03-01 08:46:32 -0600
committerJohn Estabrook <jestabro@vyos.io>2023-03-01 08:46:32 -0600
commit3204cdb1f92b8880fcc7481d17ae2a00e78c6d96 (patch)
treedc6cb9da8da937866822f780fb2fd874a4d6a9e9 /src/services/api/graphql/generate/schema_from_composite.py
parent157ac088a57fcccd9f7e8298ba87b3f29658af31 (diff)
downloadvyos-1x-3204cdb1f92b8880fcc7481d17ae2a00e78c6d96.tar.gz
vyos-1x-3204cdb1f92b8880fcc7481d17ae2a00e78c6d96.zip
graphql: T5040: use nullable key field to allow schema static generation
Schema had been dynamically generated, based on configuration setting for authentication. Add nullable field 'key' for static generation of schema regardless of key/token use.
Diffstat (limited to 'src/services/api/graphql/generate/schema_from_composite.py')
-rwxr-xr-xsrc/services/api/graphql/generate/schema_from_composite.py49
1 files changed, 3 insertions, 46 deletions
diff --git a/src/services/api/graphql/generate/schema_from_composite.py b/src/services/api/graphql/generate/schema_from_composite.py
index 61a08cb2f..d7b6e0035 100755
--- a/src/services/api/graphql/generate/schema_from_composite.py
+++ b/src/services/api/graphql/generate/schema_from_composite.py
@@ -29,9 +29,6 @@ if __package__ is None or __package__ == '':
sys.path.append("/usr/libexec/vyos/services/api")
from graphql.libs.op_mode import snake_to_pascal_case, map_type_name
from composite_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 . composite_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 @compositequery
-{%- else %}
- {{ schema_name }} : {{ schema_name }}Result @compositequery
-{%- 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 @compositemutation
-{%- else %}
- {{ schema_name }} : {{ schema_name }}Result @compositemutation
-{%- endif %}
}
"""