Skip to content

Commit 4c11cf2

Browse files
committed
Address feedback
1 parent 7504791 commit 4c11cf2

File tree

3 files changed

+27
-17
lines changed

3 files changed

+27
-17
lines changed

backend/infrahub/graphql/mutations/ipam.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
from infrahub.lock import InfrahubMultiLock, build_object_lock_name
2121
from infrahub.log import get_logger
2222

23-
from .main import InfrahubMutationMixin, InfrahubMutationOptions
23+
from .main import DeleteResult, InfrahubMutationMixin, InfrahubMutationOptions
2424

2525
if TYPE_CHECKING:
2626
from infrahub.graphql.initialization import GraphqlContext
@@ -235,7 +235,7 @@ async def mutate_delete(
235235
info: GraphQLResolveInfo,
236236
data: InputObjectType,
237237
branch: Branch,
238-
):
238+
) -> DeleteResult:
239239
return await super().mutate_delete(info=info, data=data, branch=branch)
240240

241241

@@ -402,7 +402,7 @@ async def mutate_delete(
402402
info: GraphQLResolveInfo,
403403
data: InputObjectType,
404404
branch: Branch,
405-
) -> tuple[Node, Self, list[Node]]:
405+
) -> DeleteResult:
406406
graphql_context: GraphqlContext = info.context
407407
db = graphql_context.db
408408

@@ -431,4 +431,4 @@ async def mutate_delete(
431431

432432
ok = True
433433

434-
return reconciled_prefix, cls(ok=ok), []
434+
return DeleteResult(node=reconciled_prefix, mutation=cls(ok=ok))

backend/infrahub/graphql/mutations/main.py

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from __future__ import annotations
22

3+
from dataclasses import dataclass, field
34
from typing import TYPE_CHECKING, Any, Mapping, Optional, Union
45

56
from graphene import InputObjectType, Mutation
@@ -49,6 +50,13 @@
4950
KINDS_CONCURRENT_MUTATIONS_NOT_ALLOWED = [InfrahubKind.GENERICGROUP]
5051

5152

53+
@dataclass
54+
class DeleteResult:
55+
node: Node
56+
mutation: InfrahubMutationMixin
57+
deleted_nodes: list[Node] = field(default_factory=list)
58+
59+
5260
# ------------------------------------------
5361
# Infrahub GraphQLType
5462
# ------------------------------------------
@@ -64,7 +72,7 @@ async def mutate(cls, root: dict, info: GraphQLResolveInfo, data: InputObjectTyp
6472
obj = None
6573
mutation = None
6674
action = MutationAction.UNDEFINED
67-
deleted: list[Node] = []
75+
deleted_nodes: list[Node] = []
6876

6977
if "Create" in cls.__name__:
7078
obj, mutation = await cls.mutate_create(info=info, branch=graphql_context.branch, data=data, **kwargs)
@@ -87,9 +95,11 @@ async def mutate(cls, root: dict, info: GraphQLResolveInfo, data: InputObjectTyp
8795
else:
8896
action = MutationAction.UPDATED
8997
elif "Delete" in cls.__name__:
90-
obj, mutation, deleted = await cls.mutate_delete(
91-
info=info, branch=graphql_context.branch, data=data, **kwargs
92-
)
98+
delete_result = await cls.mutate_delete(info=info, branch=graphql_context.branch, data=data, **kwargs)
99+
obj = delete_result.node
100+
mutation = delete_result.mutation
101+
deleted_nodes = delete_result.deleted_nodes
102+
93103
action = MutationAction.DELETED
94104
else:
95105
raise ValueError(
@@ -127,8 +137,8 @@ async def mutate(cls, root: dict, info: GraphQLResolveInfo, data: InputObjectTyp
127137

128138
events = [main_event]
129139

130-
deleted_changelogs = [node.node_changelog for node in deleted if node.id != obj.id]
131-
deleted_ids = [node.node_id for node in deleted_changelogs]
140+
deleted_changelogs = [node.node_changelog for node in deleted_nodes if node.id != obj.id]
141+
deleted_ids = {node.node_id for node in deleted_changelogs}
132142

133143
for node_changelog in deleted_changelogs:
134144
meta = EventMeta.from_parent(parent=main_event)
@@ -448,9 +458,9 @@ async def mutate_update_object(
448458
await node_constraint_runner.check(node=obj, field_filters=fields_to_validate)
449459

450460
fields = list(data.keys())
451-
for field in ("id", "hfid"):
452-
if field in fields:
453-
fields.remove(field)
461+
for field_to_remove in ("id", "hfid"):
462+
if field_to_remove in fields:
463+
fields.remove(field_to_remove)
454464

455465
await obj.save(db=db, fields=fields)
456466

@@ -513,7 +523,7 @@ async def mutate_delete(
513523
info: GraphQLResolveInfo,
514524
data: InputObjectType,
515525
branch: Branch,
516-
) -> tuple[Node, Self, list[Node]]:
526+
) -> DeleteResult:
517527
graphql_context: GraphqlContext = info.context
518528

519529
obj = await NodeManager.find_object(
@@ -531,7 +541,7 @@ async def mutate_delete(
531541

532542
ok = True
533543

534-
return obj, cls(ok=ok), deleted
544+
return DeleteResult(node=obj, mutation=cls(ok=ok), deleted_nodes=deleted)
535545

536546

537547
class InfrahubMutation(InfrahubMutationMixin, Mutation):

backend/infrahub/graphql/mutations/menu.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
from infrahub.exceptions import ValidationError
1515
from infrahub.graphql.mutations.main import InfrahubMutationMixin
1616

17-
from .main import InfrahubMutationOptions
17+
from .main import DeleteResult, InfrahubMutationOptions
1818

1919
if TYPE_CHECKING:
2020
from infrahub.graphql.initialization import GraphqlContext
@@ -89,7 +89,7 @@ async def mutate_delete(
8989
info: GraphQLResolveInfo,
9090
data: InputObjectType,
9191
branch: Branch,
92-
) -> tuple[Node, Self, list[Node]]:
92+
) -> DeleteResult:
9393
graphql_context: GraphqlContext = info.context
9494
obj = await NodeManager.find_object(
9595
db=graphql_context.db, kind=CoreMenuItem, id=data.get("id"), hfid=data.get("hfid"), branch=branch

0 commit comments

Comments
 (0)