diff options
author | John Estabrook <jestabro@vyos.io> | 2022-10-09 08:46:14 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-10-09 08:46:14 -0500 |
commit | 72c97ec2cb868b6208621566678dd42791e8e5c7 (patch) | |
tree | 6b523604d51b4c16e0c8693353ec57650d163022 /src/services/api/graphql/utils/util.py | |
parent | bb4901773df9682b67081dda5baf0cb39c742d1e (diff) | |
parent | 76c9a376c7d4fbb46f8882a1ce42dd7a6c0fa85a (diff) | |
download | vyos-1x-72c97ec2cb868b6208621566678dd42791e8e5c7.tar.gz vyos-1x-72c97ec2cb868b6208621566678dd42791e8e5c7.zip |
Merge pull request #1573 from jestabro/gql-simplify
T4738: generate schema definitions for configsession functions and use single directive/resolver
Diffstat (limited to 'src/services/api/graphql/utils/util.py')
-rw-r--r-- | src/services/api/graphql/utils/util.py | 24 |
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' |