@@ -48,14 +48,16 @@ def render_match(self) -> str:
4848
4949 @staticmethod
5050 def _render_sub_query_per_rel_type (
51- rel_name : str , rel_type : str , rel_def : FieldInfo , direction : GraphRelDirection
51+ rel_name : str ,
52+ rel_type : str ,
53+ rel_def : FieldInfo ,
5254 ) -> str :
5355 subquery = [
5456 f"WITH peer_node, { rel_name } , active_node, new_node" ,
5557 f"WITH peer_node, { rel_name } , active_node, new_node" ,
5658 f'WHERE type({ rel_name } ) = "{ rel_type } "' ,
5759 ]
58- if rel_def .default .direction in [direction , GraphRelDirection .EITHER ]:
60+ if rel_def .default .direction in [GraphRelDirection . OUTBOUND , GraphRelDirection .EITHER ]:
5961 subquery .append (f"""
6062 CREATE (new_node)-[new_active_edge:{ rel_type } $rel_props_new ]->(peer_node)
6163 SET new_active_edge.branch = CASE WHEN { rel_name } .branch = "-global-" THEN "-global-" ELSE $branch END
@@ -66,7 +68,7 @@ def _render_sub_query_per_rel_type(
6668 SET deleted_edge.branch = CASE WHEN { rel_name } .branch = "-global-" THEN "-global-" ELSE $branch END
6769 SET deleted_edge.branch_level = CASE WHEN { rel_name } .branch = "-global-" THEN { rel_name } .branch_level ELSE $branch_level END
6870 """ )
69- elif rel_def .default .direction in [direction , GraphRelDirection .EITHER ]:
71+ elif rel_def .default .direction in [GraphRelDirection . INBOUND , GraphRelDirection .EITHER ]:
7072 subquery .append (f"""
7173 CREATE (new_node)<-[new_active_edge:{ rel_type } $rel_props_new ]-(peer_node)
7274 SET new_active_edge.branch = CASE WHEN { rel_name } .branch = "-global-" THEN "-global-" ELSE $branch END
@@ -84,7 +86,9 @@ def _render_sub_query_per_rel_type(
8486 def _render_sub_query_out (cls ) -> str :
8587 sub_queries_out = [
8688 cls ._render_sub_query_per_rel_type (
87- rel_name = "rel_outband" , rel_type = rel_type , rel_def = rel_def , direction = GraphRelDirection .OUTBOUND
89+ rel_name = "rel_outband" ,
90+ rel_type = rel_type ,
91+ rel_def = rel_def ,
8892 )
8993 for rel_type , rel_def in GraphNodeRelationships .model_fields .items ()
9094 ]
@@ -95,7 +99,9 @@ def _render_sub_query_out(cls) -> str:
9599 def _render_sub_query_in (cls ) -> str :
96100 sub_queries_in = [
97101 cls ._render_sub_query_per_rel_type (
98- rel_name = "rel_inband" , rel_type = rel_type , rel_def = rel_def , direction = GraphRelDirection .INBOUND
102+ rel_name = "rel_inband" ,
103+ rel_type = rel_type ,
104+ rel_def = rel_def ,
99105 )
100106 for rel_type , rel_def in GraphNodeRelationships .model_fields .items ()
101107 ]
@@ -140,7 +146,7 @@ async def query_init(self, db: InfrahubDatabase, **kwargs: dict[str, Any]) -> No
140146 LIMIT 1
141147 }
142148 WITH n1 as active_node, r1 as rb
143- WHERE rb.status = "active" AND rb.to IS NULL
149+ WHERE rb.status = "active"
144150 CREATE (new_node:Node:%(labels)s { uuid: active_node.uuid, kind: $new_node.kind, namespace: $new_node.namespace, branch_support: $new_node.branch_support })
145151 WITH active_node, new_node
146152 // Process Outbound Relationship
@@ -159,10 +165,10 @@ async def query_init(self, db: InfrahubDatabase, **kwargs: dict[str, Any]) -> No
159165 %(sub_query_out)s
160166 }
161167 WITH p2 as peer_node, rel_outband, active_node, new_node
162- FOREACH (i in CASE WHEN rel_outband.branch = "-global-" or rel_outband.branch = $branch THEN [1] ELSE [] END |
168+ FOREACH (i in CASE WHEN rel_outband.branch IN [ "-global-", $branch] THEN [1] ELSE [] END |
163169 SET rel_outband.to = $current_time
164170 )
165- WITH peer_node, rel_outband, active_node, new_node
171+ WITH active_node, new_node
166172 MATCH (active_node)<-[]-(peer)
167173 CALL {
168174 WITH active_node, peer
0 commit comments