@@ -219,7 +219,7 @@ def set_context_properties(
219219 delete_unused_nodes = delete_unused_nodes ,
220220 group_type = group_type ,
221221 group_params = group_params ,
222- branch = branch ,
222+ branch = branch or self . default_branch ,
223223 )
224224
225225 def _graphql_url (
@@ -320,8 +320,7 @@ async def get_version(self) -> str:
320320
321321 async def get_user (self ) -> dict :
322322 """Return user information"""
323- user_info = await self .execute_graphql (query = QUERY_USER )
324- return user_info
323+ return await self .execute_graphql (query = QUERY_USER )
325324
326325 async def get_user_permissions (self ) -> dict :
327326 """Return user permissions"""
@@ -550,6 +549,7 @@ async def _process_nodes_and_relationships(
550549 schema_kind : str ,
551550 branch : str ,
552551 prefetch_relationships : bool ,
552+ include : list [str ] | None ,
553553 timeout : int | None = None ,
554554 ) -> ProcessRelationsNode :
555555 """Processes InfrahubNode and their Relationships from the GraphQL query response.
@@ -574,9 +574,12 @@ async def _process_nodes_and_relationships(
574574 node = await InfrahubNode .from_graphql (client = self , branch = branch , data = item , timeout = timeout )
575575 nodes .append (node )
576576
577- if prefetch_relationships :
577+ if prefetch_relationships or ( include and any ( rel in include for rel in node . _relationships )) :
578578 await node ._process_relationships (
579- node_data = item , branch = branch , related_nodes = related_nodes , timeout = timeout
579+ node_data = item ,
580+ branch = branch ,
581+ related_nodes = related_nodes ,
582+ timeout = timeout ,
580583 )
581584
582585 return ProcessRelationsNode (nodes = nodes , related_nodes = related_nodes )
@@ -826,6 +829,7 @@ async def process_page(page_offset: int, page_number: int) -> tuple[dict, Proces
826829 branch = branch ,
827830 prefetch_relationships = prefetch_relationships ,
828831 timeout = timeout ,
832+ include = include ,
829833 )
830834 return response , process_result
831835
@@ -1119,13 +1123,13 @@ async def query_gql_query(
11191123
11201124 url = f"{ self .address } /api/query/{ name } "
11211125 url_params = copy .deepcopy (params or {})
1126+ url_params ["branch" ] = branch_name or self .default_branch
1127+
11221128 headers = copy .copy (self .headers or {})
11231129
11241130 if self .insert_tracker and tracker :
11251131 headers ["X-Infrahub-Tracker" ] = tracker
11261132
1127- if branch_name :
1128- url_params ["branch" ] = branch_name
11291133 if at :
11301134 url_params ["at" ] = at
11311135
@@ -1581,8 +1585,7 @@ def get_version(self) -> str:
15811585
15821586 def get_user (self ) -> dict :
15831587 """Return user information"""
1584- user_info = self .execute_graphql (query = QUERY_USER )
1585- return user_info
1588+ return self .execute_graphql (query = QUERY_USER )
15861589
15871590 def get_user_permissions (self ) -> dict :
15881591 """Return user permissions"""
@@ -1852,6 +1855,7 @@ def _process_nodes_and_relationships(
18521855 schema_kind : str ,
18531856 branch : str ,
18541857 prefetch_relationships : bool ,
1858+ include : list [str ] | None ,
18551859 timeout : int | None = None ,
18561860 ) -> ProcessRelationsNodeSync :
18571861 """Processes InfrahubNodeSync and their Relationships from the GraphQL query response.
@@ -1876,7 +1880,7 @@ def _process_nodes_and_relationships(
18761880 node = InfrahubNodeSync .from_graphql (client = self , branch = branch , data = item , timeout = timeout )
18771881 nodes .append (node )
18781882
1879- if prefetch_relationships :
1883+ if prefetch_relationships or ( include and any ( rel in include for rel in node . _relationships )) :
18801884 node ._process_relationships (node_data = item , branch = branch , related_nodes = related_nodes , timeout = timeout )
18811885
18821886 return ProcessRelationsNodeSync (nodes = nodes , related_nodes = related_nodes )
@@ -2001,6 +2005,7 @@ def process_page(page_offset: int, page_number: int) -> tuple[dict, ProcessRelat
20012005 branch = branch ,
20022006 prefetch_relationships = prefetch_relationships ,
20032007 timeout = timeout ,
2008+ include = include ,
20042009 )
20052010 return response , process_result
20062011
@@ -2265,13 +2270,13 @@ def query_gql_query(
22652270
22662271 url = f"{ self .address } /api/query/{ name } "
22672272 url_params = copy .deepcopy (params or {})
2273+ url_params ["branch" ] = branch_name or self .default_branch
2274+
22682275 headers = copy .copy (self .headers or {})
22692276
22702277 if self .insert_tracker and tracker :
22712278 headers ["X-Infrahub-Tracker" ] = tracker
22722279
2273- if branch_name :
2274- url_params ["branch" ] = branch_name
22752280 if at :
22762281 url_params ["at" ] = at
22772282 if subscribers :
0 commit comments