Skip to content
Merged
Changes from all commits
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
34 changes: 26 additions & 8 deletions infrahub_sdk/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -562,18 +562,27 @@
at: Timestamp | None = None,
branch: str | None = None,
timeout: int | None = None,
partial_match: bool = False,
**kwargs: Any,
) -> int:
"""Return the number of nodes of a given kind."""
filters = kwargs
schema = await self.schema.get(kind=kind, branch=branch)
filters: dict[str, Any] = dict(kwargs)

if partial_match:
filters["partial_match"] = True

Check warning on line 572 in infrahub_sdk/client.py

View check run for this annotation

Codecov / codecov/patch

infrahub_sdk/client.py#L572

Added line #L572 was not covered by tests

schema = await self.schema.get(kind=kind, branch=branch)
branch = branch or self.default_branch
if at:
at = Timestamp(at)

data: dict[str, Any] = {
"count": None,
"@filters": filters,
}

response = await self.execute_graphql(
query=Query(query={schema.kind: {"count": None, "@filters": filters}}).render(),
query=Query(query={schema.kind: data}).render(),
branch_name=branch,
at=at,
timeout=timeout,
Expand Down Expand Up @@ -801,7 +810,7 @@
nodes = []
related_nodes = []
batch_process = await self.create_batch()
count = await self.count(kind=schema.kind, **filters)
count = await self.count(kind=schema.kind, partial_match=partial_match, **filters)
total_pages = (count + pagination_size - 1) // pagination_size

for page_number in range(1, total_pages + 1):
Expand Down Expand Up @@ -1683,18 +1692,27 @@
at: Timestamp | None = None,
branch: str | None = None,
timeout: int | None = None,
partial_match: bool = False,
**kwargs: Any,
) -> int:
"""Return the number of nodes of a given kind."""
filters = kwargs
schema = self.schema.get(kind=kind, branch=branch)
filters: dict[str, Any] = dict(kwargs)

if partial_match:
filters["partial_match"] = True

Check warning on line 1702 in infrahub_sdk/client.py

View check run for this annotation

Codecov / codecov/patch

infrahub_sdk/client.py#L1702

Added line #L1702 was not covered by tests

schema = self.schema.get(kind=kind, branch=branch)
branch = branch or self.default_branch
if at:
at = Timestamp(at)

data: dict[str, Any] = {
"count": None,
"@filters": filters,
}

response = self.execute_graphql(
query=Query(query={schema.kind: {"count": None, "@filters": filters}}).render(),
query=Query(query={schema.kind: data}).render(),
branch_name=branch,
at=at,
timeout=timeout,
Expand Down Expand Up @@ -1957,7 +1975,7 @@
related_nodes = []
batch_process = self.create_batch()

count = self.count(kind=schema.kind, **filters)
count = self.count(kind=schema.kind, partial_match=partial_match, **filters)
total_pages = (count + pagination_size - 1) // pagination_size

for page_number in range(1, total_pages + 1):
Expand Down