Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IFC-248 - Branch parameters in SDK #4056

Merged
merged 6 commits into from
Aug 9, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion python_sdk/infrahub_sdk/checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class InfrahubCheck:

def __init__(
self,
branch: str = "",
branch: Optional[str] = None,
root_directory: str = "",
output: Optional[str] = None,
initializer: Optional[InfrahubCheckInitializer] = None,
Expand Down
4 changes: 2 additions & 2 deletions python_sdk/infrahub_sdk/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,7 @@ async def filters(
Returns:
list[InfrahubNodeSync]: List of Nodes that match the given filters.
"""
schema = await self.schema.get(kind=kind)
schema = await self.schema.get(kind=kind, branch=branch)

branch = branch or self.default_branch
if at:
Expand Down Expand Up @@ -1262,7 +1262,7 @@ def filters(
Returns:
list[InfrahubNodeSync]: List of Nodes that match the given filters.
"""
schema = self.schema.get(kind=kind)
schema = self.schema.get(kind=kind, branch=branch)

branch = branch or self.default_branch
if at:
Expand Down
4 changes: 2 additions & 2 deletions python_sdk/infrahub_sdk/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,10 @@ async def process_nodes(self, data: dict) -> None:
for kind in data:
if kind in self._init_client.schema.cache[self.branch_name]:
for result in data[kind].get("edges", []):
node = await self.infrahub_node.from_graphql(client=self._init_client, branch="main", data=result)
node = await self.infrahub_node.from_graphql(client=self._init_client, branch=self.branch_name, data=result)
self._nodes.append(node)
await node._process_relationships(
node_data=result, branch="main", related_nodes=self._related_nodes
node_data=result, branch=self.branch_name, related_nodes=self._related_nodes
)

for node in self._nodes + self._related_nodes:
Expand Down
8 changes: 4 additions & 4 deletions python_sdk/infrahub_sdk/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -1064,7 +1064,7 @@ async def from_graphql(
node_kind = data.get("__typename", None) or data.get("node", {}).get("__typename", None)
if not node_kind:
raise ValueError("Unable to determine the type of the node, __typename not present in data")
schema = await client.schema.get(kind=node_kind)
schema = await client.schema.get(kind=node_kind, branch=branch)

return cls(client=client, schema=schema, branch=branch, data=cls._strip_alias(data))

Expand Down Expand Up @@ -1264,7 +1264,7 @@ async def generate_query_data_node(

peer_data: dict[str, Any] = {}
if rel_schema and prefetch_relationships:
peer_schema = await self._client.schema.get(kind=rel_schema.peer)
peer_schema = await self._client.schema.get(kind=rel_schema.peer, branch=self._branch)
peer_node = InfrahubNode(client=self._client, schema=peer_schema, branch=self._branch)
peer_data = await peer_node.generate_query_data_node(include=include, exclude=exclude, inherited=False)

Expand Down Expand Up @@ -1528,7 +1528,7 @@ def from_graphql(
node_kind = data.get("__typename", None) or data.get("node", {}).get("__typename", None)
if not node_kind:
raise ValueError("Unable to determine the type of the node, __typename not present in data")
schema = client.schema.get(kind=node_kind)
schema = client.schema.get(kind=node_kind, branch=branch)

return cls(client=client, schema=schema, branch=branch, data=cls._strip_alias(data))

Expand Down Expand Up @@ -1720,7 +1720,7 @@ def generate_query_data_node(

peer_data: dict[str, Any] = {}
if rel_schema and prefetch_relationships:
peer_schema = self._client.schema.get(kind=rel_schema.peer)
peer_schema = self._client.schema.get(kind=rel_schema.peer, branch=self._branch)
peer_node = InfrahubNodeSync(client=self._client, schema=peer_schema, branch=self._branch)
peer_data = peer_node.generate_query_data_node(include=include, exclude=exclude, inherited=False)

Expand Down
Loading