From 296412a6fdb23c3b5791de8355b6c41dd17f18f8 Mon Sep 17 00:00:00 2001 From: Inex Code Date: Wed, 3 Jul 2024 17:52:21 +0400 Subject: [PATCH] fix --- .../graphql/common_types/service.py | 46 ++++++++++--------- 1 file changed, 24 insertions(+), 22 deletions(-) diff --git a/selfprivacy_api/graphql/common_types/service.py b/selfprivacy_api/graphql/common_types/service.py index 71ed69c..9223b9a 100644 --- a/selfprivacy_api/graphql/common_types/service.py +++ b/selfprivacy_api/graphql/common_types/service.py @@ -134,34 +134,36 @@ class EnumConfigItem(ConfigItem): options: list[str] -def config_item_to_graphql(item: ServiceConfigItem) -> ConfigItem: - if isinstance(item, StringServiceConfigItem): +def config_item_to_graphql(item: dict) -> ConfigItem: + item_type = item.get("type") + if item_type == "string": return StringConfigItem( - id=item.id, - description=item.description, - widget=item.widget, - type=item.type, - value=item.default_value, - regex=item.regex.pattern if item.regex else None, + id=item["id"], + description=item["description"], + widget=item["widget"], + type=item_type, + value=item["default_value"], + regex=item.get("regex") ) - if isinstance(item, BoolServiceConfigItem): + elif item_type == "bool": return BoolConfigItem( - id=item.id, - description=item.description, - widget=item.widget, - type=item.type, - value=item.default_value, + id=item["id"], + description=item["description"], + widget=item["widget"], + type=item_type, + value=item["default_value"], ) - if isinstance(item, EnumServiceConfigItem): + elif item_type == "enum": return EnumConfigItem( - id=item.id, - description=item.description, - widget=item.widget, - type=item.type, - value=item.default_value, - options=item.options, + id=item["id"], + description=item["description"], + widget=item["widget"], + type=item_type, + value=item["default_value"], + options=item["options"], ) - raise ValueError(f"Unknown config item type {item}") + else: + raise ValueError(f"Unknown config item type {item_type}") @strawberry.type