This commit is contained in:
Inex Code 2024-07-03 17:52:21 +04:00
parent 17831668af
commit 296412a6fd

View file

@ -134,34 +134,36 @@ class EnumConfigItem(ConfigItem):
options: list[str] options: list[str]
def config_item_to_graphql(item: ServiceConfigItem) -> ConfigItem: def config_item_to_graphql(item: dict) -> ConfigItem:
if isinstance(item, StringServiceConfigItem): item_type = item.get("type")
if item_type == "string":
return StringConfigItem( return StringConfigItem(
id=item.id, id=item["id"],
description=item.description, description=item["description"],
widget=item.widget, widget=item["widget"],
type=item.type, type=item_type,
value=item.default_value, value=item["default_value"],
regex=item.regex.pattern if item.regex else None, regex=item.get("regex")
) )
if isinstance(item, BoolServiceConfigItem): elif item_type == "bool":
return BoolConfigItem( return BoolConfigItem(
id=item.id, id=item["id"],
description=item.description, description=item["description"],
widget=item.widget, widget=item["widget"],
type=item.type, type=item_type,
value=item.default_value, value=item["default_value"],
) )
if isinstance(item, EnumServiceConfigItem): elif item_type == "enum":
return EnumConfigItem( return EnumConfigItem(
id=item.id, id=item["id"],
description=item.description, description=item["description"],
widget=item.widget, widget=item["widget"],
type=item.type, type=item_type,
value=item.default_value, value=item["default_value"],
options=item.options, options=item["options"],
) )
raise ValueError(f"Unknown config item type {item}") else:
raise ValueError(f"Unknown config item type {item_type}")
@strawberry.type @strawberry.type