Skip to content

Commit 86a0293

Browse files
committed
Rename all_pb_names to all_product_block_names and refactor related logic for clarity
1 parent fc4c57e commit 86a0293

File tree

2 files changed

+10
-11
lines changed

2 files changed

+10
-11
lines changed

orchestrator/graphql/schemas/product.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -52,21 +52,20 @@ async def subscriptions(
5252
return await resolve_subscriptions(info, filter_by_with_related_subscriptions, sort_by, first, after)
5353

5454
@strawberry.field(description="Returns list of all nested productblock names") # type: ignore
55-
async def all_pb_names(self) -> list[str]:
56-
55+
async def all_product_block_names(self) -> list[str]:
5756
model = get_original_model(self, ProductTable)
5857

59-
def get_all_pb_names(product_blocks: list[ProductBlockTable]) -> Iterable[str]:
58+
def get_names(product_blocks: list[ProductBlockTable], visited: set) -> Iterable[str]:
6059
for product_block in product_blocks:
60+
if product_block.product_block_id in visited:
61+
continue
62+
visited.add(product_block.product_block_id)
6163
yield product_block.name
62-
6364
if product_block.depends_on:
64-
yield from get_all_pb_names(product_block.depends_on)
65-
66-
names: list[str] = list(get_all_pb_names(model.product_blocks))
67-
names.sort()
65+
yield from get_names(product_block.depends_on, visited)
6866

69-
return names
67+
names = set(get_names(model.product_blocks, set()))
68+
return sorted(names)
7069

7170
@strawberry.field(description="Return product blocks") # type: ignore
7271
async def product_blocks(self) -> list[Annotated["ProductBlock", strawberry.lazy(".product_block")]]:

test/unit_tests/graphql/test_product.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ def get_all_product_names_query(
8585
query ProductQuery($filterBy: [GraphqlFilter!]) {
8686
products(filterBy: $filterBy) {
8787
page {
88-
allPbNames
88+
allProductBlockNames
8989
}
9090
pageInfo {
9191
endCursor
@@ -235,7 +235,7 @@ def test_all_product_block_names(test_client, generic_product_4):
235235
result = response.json()
236236
products_data = result["data"]["products"]
237237
products = products_data["page"]
238-
names = products[0]["allPbNames"]
238+
names = products[0]["allProductBlockNames"]
239239

240240
assert len(names) == 2
241241

0 commit comments

Comments
 (0)