99
1010from infrahub .core .branch import Branch
1111from infrahub .database import retry_db_transaction
12+ from infrahub .graphql .context import apply_external_context
13+ from infrahub .graphql .types .context import ContextInput
1214from infrahub .log import get_logger
1315from infrahub .workflows .catalogue import (
1416 BRANCH_CREATE ,
@@ -44,6 +46,7 @@ class BranchCreateInput(InputObjectType):
4446class BranchCreate (Mutation ):
4547 class Arguments :
4648 data = BranchCreateInput (required = True )
49+ context = ContextInput (required = False )
4750 background_execution = Boolean (required = False , deprecation_reason = "Please use `wait_until_completion` instead" )
4851 wait_until_completion = Boolean (required = False )
4952
@@ -58,13 +61,15 @@ async def mutate(
5861 root : dict , # noqa: ARG003
5962 info : GraphQLResolveInfo ,
6063 data : BranchCreateInput ,
64+ context : ContextInput | None = None ,
6165 background_execution : bool = False ,
6266 wait_until_completion : bool = True ,
6367 ) -> Self :
6468 graphql_context : GraphqlContext = info .context
6569 task : dict | None = None
6670
6771 model = BranchCreateModel (** data )
72+ await apply_external_context (graphql_context = graphql_context , context_input = context )
6873
6974 if background_execution or not wait_until_completion :
7075 workflow = await graphql_context .active_service .workflow .submit_workflow (
@@ -96,6 +101,7 @@ class BranchUpdateInput(InputObjectType):
96101class BranchDelete (Mutation ):
97102 class Arguments :
98103 data = BranchNameInput (required = True )
104+ context = ContextInput (required = False )
99105 wait_until_completion = Boolean (required = False )
100106
101107 ok = Boolean ()
@@ -107,10 +113,12 @@ async def mutate(
107113 root : dict , # noqa: ARG003
108114 info : GraphQLResolveInfo ,
109115 data : BranchNameInput ,
116+ context : ContextInput | None = None ,
110117 wait_until_completion : bool = True ,
111118 ) -> Self :
112119 graphql_context : GraphqlContext = info .context
113120 obj = await Branch .get_by_name (db = graphql_context .db , name = str (data .name ))
121+ await apply_external_context (graphql_context = graphql_context , context_input = context )
114122
115123 if wait_until_completion :
116124 await graphql_context .active_service .workflow .execute_workflow (
@@ -127,15 +135,23 @@ async def mutate(
127135class BranchUpdate (Mutation ):
128136 class Arguments :
129137 data = BranchUpdateInput (required = True )
138+ context = ContextInput (required = False )
130139
131140 ok = Boolean ()
132141
133142 @classmethod
134143 @retry_db_transaction (name = "branch_update" )
135- async def mutate (cls , root : dict , info : GraphQLResolveInfo , data : BranchNameInput ) -> Self : # noqa: ARG003
144+ async def mutate (
145+ cls ,
146+ root : dict , # noqa: ARG003
147+ info : GraphQLResolveInfo ,
148+ data : BranchNameInput ,
149+ context : ContextInput | None = None ,
150+ ) -> Self :
136151 graphql_context : GraphqlContext = info .context
137152
138153 obj = await Branch .get_by_name (db = graphql_context .db , name = data ["name" ])
154+ await apply_external_context (graphql_context = graphql_context , context_input = context )
139155
140156 to_extract = ["description" ]
141157 for field_name in to_extract :
@@ -151,6 +167,7 @@ async def mutate(cls, root: dict, info: GraphQLResolveInfo, data: BranchNameInpu
151167class BranchRebase (Mutation ):
152168 class Arguments :
153169 data = BranchNameInput (required = True )
170+ context = ContextInput (required = False )
154171 wait_until_completion = Boolean (required = False )
155172
156173 ok = Boolean ()
@@ -163,11 +180,13 @@ async def mutate(
163180 root : dict , # noqa: ARG003
164181 info : GraphQLResolveInfo ,
165182 data : BranchNameInput ,
183+ context : ContextInput | None = None ,
166184 wait_until_completion : bool = True ,
167185 ) -> Self :
168186 graphql_context : GraphqlContext = info .context
169187
170188 obj = await Branch .get_by_name (db = graphql_context .db , name = str (data .name ))
189+ await apply_external_context (graphql_context = graphql_context , context_input = context )
171190 task : dict | None = None
172191
173192 if wait_until_completion :
@@ -192,6 +211,7 @@ async def mutate(
192211class BranchValidate (Mutation ):
193212 class Arguments :
194213 data = BranchNameInput (required = True )
214+ context = ContextInput (required = False )
195215 wait_until_completion = Boolean (required = False )
196216
197217 ok = Boolean ()
@@ -205,11 +225,13 @@ async def mutate(
205225 root : dict , # noqa: ARG003
206226 info : GraphQLResolveInfo ,
207227 data : BranchNameInput ,
228+ context : ContextInput | None = None ,
208229 wait_until_completion : bool = True ,
209230 ) -> Self :
210231 graphql_context : GraphqlContext = info .context
211232
212233 obj = await Branch .get_by_name (db = graphql_context .db , name = str (data .name ))
234+ await apply_external_context (graphql_context = graphql_context , context_input = context )
213235 task : dict | None = None
214236 ok = True
215237
@@ -231,6 +253,7 @@ async def mutate(
231253class BranchMerge (Mutation ):
232254 class Arguments :
233255 data = BranchNameInput (required = True )
256+ context = ContextInput (required = False )
234257 wait_until_completion = Boolean (required = False )
235258
236259 ok = Boolean ()
@@ -243,11 +266,13 @@ async def mutate(
243266 root : dict , # noqa: ARG003
244267 info : GraphQLResolveInfo ,
245268 data : BranchNameInput ,
269+ context : ContextInput | None = None ,
246270 wait_until_completion : bool = True ,
247271 ) -> Self :
248272 branch_name = data ["name" ]
249273 task : dict | None = None
250274 graphql_context : GraphqlContext = info .context
275+ await apply_external_context (graphql_context = graphql_context , context_input = context )
251276
252277 if wait_until_completion :
253278 await graphql_context .active_service .workflow .execute_workflow (
0 commit comments