summaryrefslogtreecommitdiff
path: root/src/services/api/graphql/utils/util.py
diff options
context:
space:
mode:
authorJohn Estabrook <jestabro@vyos.io>2022-10-06 15:37:19 -0500
committerJohn Estabrook <jestabro@vyos.io>2022-10-07 15:00:41 -0500
commit5f81ced8d57d3e315252abc58e777ff946ccf494 (patch)
tree39e3cd828df579fbe11e756b824b3c0456437420 /src/services/api/graphql/utils/util.py
parentbb4901773df9682b67081dda5baf0cb39c742d1e (diff)
downloadvyos-1x-5f81ced8d57d3e315252abc58e777ff946ccf494.tar.gz
vyos-1x-5f81ced8d57d3e315252abc58e777ff946ccf494.zip
graphql: T4738: generate schema defs for configsession methods
Diffstat (limited to 'src/services/api/graphql/utils/util.py')
-rw-r--r--src/services/api/graphql/utils/util.py24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/services/api/graphql/utils/util.py b/src/services/api/graphql/utils/util.py
index 073126853..da2bcdb5b 100644
--- a/src/services/api/graphql/utils/util.py
+++ b/src/services/api/graphql/utils/util.py
@@ -15,6 +15,7 @@
import os
import re
+import typing
import importlib.util
from vyos.defaults import directories
@@ -74,3 +75,26 @@ def split_compound_op_mode_name(name: str, files: list):
pair = (pair[0], f[0])
return pair
return (name, '')
+
+def snake_to_pascal_case(name: str) -> str:
+ res = ''.join(map(str.title, name.split('_')))
+ return res
+
+def map_type_name(type_name: type, optional: bool = False) -> str:
+ if type_name == str:
+ return 'String!' if not optional else 'String = null'
+ if type_name == int:
+ return 'Int!' if not optional else 'Int = null'
+ if type_name == bool:
+ return 'Boolean!' if not optional else 'Boolean = false'
+ if typing.get_origin(type_name) == list:
+ if not optional:
+ return f'[{map_type_name(typing.get_args(type_name)[0])}]!'
+ return f'[{map_type_name(typing.get_args(type_name)[0])}]'
+ # typing.Optional is typing.Union[_, NoneType]
+ if (typing.get_origin(type_name) is typing.Union and
+ typing.get_args(type_name)[1] == type(None)):
+ return f'{map_type_name(typing.get_args(type_name)[0], optional=True)}'
+
+ # scalar 'Generic' is defined in schema.graphql
+ return 'Generic'