diff --git a/orchestrator/graphql/schemas/product.py b/orchestrator/graphql/schemas/product.py index 0a679536f..dc68c8a36 100644 --- a/orchestrator/graphql/schemas/product.py +++ b/orchestrator/graphql/schemas/product.py @@ -52,21 +52,20 @@ async def subscriptions( return await resolve_subscriptions(info, filter_by_with_related_subscriptions, sort_by, first, after) @strawberry.field(description="Returns list of all nested productblock names") # type: ignore - async def all_pb_names(self) -> list[str]: - + async def all_product_block_names(self) -> list[str]: model = get_original_model(self, ProductTable) - def get_all_pb_names(product_blocks: list[ProductBlockTable]) -> Iterable[str]: + def get_names(product_blocks: list[ProductBlockTable], visited: set) -> Iterable[str]: for product_block in product_blocks: + if product_block.product_block_id in visited: + continue + visited.add(product_block.product_block_id) yield product_block.name - if product_block.depends_on: - yield from get_all_pb_names(product_block.depends_on) - - names: list[str] = list(get_all_pb_names(model.product_blocks)) - names.sort() + yield from get_names(product_block.depends_on, visited) - return names + names = set(get_names(model.product_blocks, set())) + return sorted(names) @strawberry.field(description="Return product blocks") # type: ignore async def product_blocks(self) -> list[Annotated["ProductBlock", strawberry.lazy(".product_block")]]: diff --git a/test/unit_tests/graphql/test_product.py b/test/unit_tests/graphql/test_product.py index 1ea1b27ab..5e6bee433 100644 --- a/test/unit_tests/graphql/test_product.py +++ b/test/unit_tests/graphql/test_product.py @@ -85,7 +85,7 @@ def get_all_product_names_query( query ProductQuery($filterBy: [GraphqlFilter!]) { products(filterBy: $filterBy) { page { - allPbNames + allProductBlockNames } pageInfo { endCursor @@ -235,7 +235,7 @@ def test_all_product_block_names(test_client, generic_product_4): result = response.json() products_data = result["data"]["products"] products = products_data["page"] - names = products[0]["allPbNames"] + names = products[0]["allProductBlockNames"] assert len(names) == 2