1010import  yaml 
1111from  infrahub_sdk  import  InfrahubClient   # noqa: TC002 
1212from  infrahub_sdk .exceptions  import  ValidationError 
13+ from  infrahub_sdk .node  import  InfrahubNode 
1314from  infrahub_sdk .protocols  import  (
1415    CoreArtifact ,
1516    CoreArtifactDefinition ,
5354    import  types 
5455
5556    from  infrahub_sdk .checks  import  InfrahubCheck 
56-     from  infrahub_sdk .node  import  InfrahubNode 
5757    from  infrahub_sdk .schema .repository  import  InfrahubRepositoryArtifactDefinitionConfig 
5858    from  infrahub_sdk .transforms  import  InfrahubTransform 
5959
@@ -123,6 +123,10 @@ class TransformPythonInformation(BaseModel):
123123    timeout : int 
124124    """Timeout for the function.""" 
125125
126+     convert_query_response : bool  =  Field (
127+         ..., description = "Indicate if the transform should convert the query response to InfrahubNode objects" 
128+     )
129+ 
126130
127131class  InfrahubRepositoryIntegrator (InfrahubRepositoryBase ):
128132    """ 
@@ -874,6 +878,7 @@ async def get_python_transforms(
874878                    file_path = file_path ,
875879                    query = str (graphql_query .id ),
876880                    timeout = transform_class .timeout ,
881+                     convert_query_response = transform .convert_query_response ,
877882                )
878883            )
879884
@@ -1005,6 +1010,7 @@ async def create_python_transform(
10051010            "file_path" : transform .file_path ,
10061011            "class_name" : transform .class_name ,
10071012            "timeout" : transform .timeout ,
1013+             "convert_query_response" : transform .convert_query_response ,
10081014        }
10091015        create_payload  =  self .sdk .schema .generate_payload_create (
10101016            schema = schema ,
@@ -1028,6 +1034,9 @@ async def update_python_transform(
10281034        if  existing_transform .timeout .value  !=  local_transform .timeout :
10291035            existing_transform .timeout .value  =  local_transform .timeout 
10301036
1037+         if  existing_transform .convert_query_response .value  !=  local_transform .convert_query_response :
1038+             existing_transform .convert_query_response .value  =  local_transform .convert_query_response 
1039+ 
10311040        await  existing_transform .save ()
10321041
10331042    @classmethod  
@@ -1038,6 +1047,7 @@ async def compare_python_transform(
10381047            existing_transform .query .id  !=  local_transform .query 
10391048            or  existing_transform .file_path .value  !=  local_transform .file_path 
10401049            or  existing_transform .timeout .value  !=  local_transform .timeout 
1050+             or  existing_transform .convert_query_response .value  !=  local_transform .convert_query_response 
10411051        ):
10421052            return  False 
10431053        return  True 
@@ -1129,7 +1139,13 @@ async def execute_python_check(
11291139
11301140    @task (name = "python-transform-execute" , task_run_name = "Execute Python Transform" , cache_policy = NONE )  # type: ignore[arg-type]  
11311141    async  def  execute_python_transform (
1132-         self , branch_name : str , commit : str , location : str , client : InfrahubClient , data : dict  |  None  =  None 
1142+         self ,
1143+         branch_name : str ,
1144+         commit : str ,
1145+         location : str ,
1146+         client : InfrahubClient ,
1147+         convert_query_response : bool ,
1148+         data : dict  |  None  =  None ,
11331149    ) ->  Any :
11341150        """Execute A Python Transform stored in the repository.""" 
11351151        log  =  get_run_logger ()
@@ -1159,7 +1175,13 @@ async def execute_python_transform(
11591175
11601176            transform_class : type [InfrahubTransform ] =  getattr (module , class_name )
11611177
1162-             transform  =  transform_class (root_directory = commit_worktree .directory , branch = branch_name , client = client )
1178+             transform  =  transform_class (
1179+                 root_directory = commit_worktree .directory ,
1180+                 branch = branch_name ,
1181+                 client = client ,
1182+                 convert_query_response = convert_query_response ,
1183+                 infrahub_node = InfrahubNode ,
1184+             )
11631185            return  await  transform .run (data = data )
11641186
11651187        except  ModuleNotFoundError  as  exc :
@@ -1216,6 +1238,7 @@ async def artifact_generate(
12161238                location = transformation_location ,
12171239                data = response ,
12181240                client = self .sdk ,
1241+                 convert_query_response = transformation .convert_query_response .value ,
12191242            )  # type: ignore[misc] 
12201243
12211244        if  definition .content_type .value  ==  ContentType .APPLICATION_JSON .value  and  isinstance (artifact_content , dict ):
@@ -1275,6 +1298,7 @@ async def render_artifact(
12751298                location = message .transform_location ,
12761299                data = response ,
12771300                client = self .sdk ,
1301+                 convert_query_response = message .convert_query_response ,
12781302            )  # type: ignore[misc] 
12791303
12801304        if  message .content_type  ==  ContentType .APPLICATION_JSON .value  and  isinstance (artifact_content , dict ):
0 commit comments