|
58 | 58 | from types import TracebackType |
59 | 59 |
|
60 | 60 |
|
61 | | -# pylint: disable=redefined-builtin disable=too-many-lines |
62 | | - |
63 | 61 | SchemaType = TypeVar("SchemaType", bound=CoreNode) |
64 | 62 | SchemaTypeSync = TypeVar("SchemaTypeSync", bound=CoreNodeSync) |
65 | 63 |
|
@@ -543,6 +541,25 @@ async def _process_nodes_and_relationships( |
543 | 541 |
|
544 | 542 | return ProcessRelationsNode(nodes=nodes, related_nodes=related_nodes) |
545 | 543 |
|
| 544 | + async def count( |
| 545 | + self, |
| 546 | + kind: str | type[SchemaType], |
| 547 | + at: Timestamp | None = None, |
| 548 | + branch: str | None = None, |
| 549 | + timeout: int | None = None, |
| 550 | + ) -> int: |
| 551 | + """Return the number of nodes of a given kind.""" |
| 552 | + schema = await self.schema.get(kind=kind, branch=branch) |
| 553 | + |
| 554 | + branch = branch or self.default_branch |
| 555 | + if at: |
| 556 | + at = Timestamp(at) |
| 557 | + |
| 558 | + response = await self.execute_graphql( |
| 559 | + query=Query(query={schema.kind: {"count": None}}).render(), branch_name=branch, at=at, timeout=timeout |
| 560 | + ) |
| 561 | + return int(response.get(schema.kind, {}).get("count", 0)) |
| 562 | + |
546 | 563 | @overload |
547 | 564 | async def all( |
548 | 565 | self, |
@@ -727,7 +744,7 @@ async def filters( |
727 | 744 | fragment=fragment, |
728 | 745 | prefetch_relationships=prefetch_relationships, |
729 | 746 | partial_match=partial_match, |
730 | | - # property=property, |
| 747 | + property=property, |
731 | 748 | ) |
732 | 749 | query = Query(query=query_data) |
733 | 750 | response = await self.execute_graphql( |
@@ -1163,7 +1180,7 @@ async def allocate_next_ip_address( |
1163 | 1180 | async def allocate_next_ip_address( |
1164 | 1181 | self, |
1165 | 1182 | resource_pool: CoreNode, |
1166 | | - kind: type[SchemaType] | None = None, # pylint: disable=unused-argument |
| 1183 | + kind: type[SchemaType] | None = None, # noqa: ARG002 |
1167 | 1184 | identifier: str | None = None, |
1168 | 1185 | prefix_length: int | None = None, |
1169 | 1186 | address_type: str | None = None, |
@@ -1313,7 +1330,7 @@ async def allocate_next_ip_prefix( |
1313 | 1330 | async def allocate_next_ip_prefix( |
1314 | 1331 | self, |
1315 | 1332 | resource_pool: CoreNode, |
1316 | | - kind: type[SchemaType] | None = None, # pylint: disable=unused-argument |
| 1333 | + kind: type[SchemaType] | None = None, # noqa: ARG002 |
1317 | 1334 | identifier: str | None = None, |
1318 | 1335 | prefix_length: int | None = None, |
1319 | 1336 | member_type: str | None = None, |
@@ -1583,6 +1600,25 @@ def execute_graphql( |
1583 | 1600 |
|
1584 | 1601 | # TODO add a special method to execute mutation that will check if the method returned OK |
1585 | 1602 |
|
| 1603 | + def count( |
| 1604 | + self, |
| 1605 | + kind: str | type[SchemaType], |
| 1606 | + at: Timestamp | None = None, |
| 1607 | + branch: str | None = None, |
| 1608 | + timeout: int | None = None, |
| 1609 | + ) -> int: |
| 1610 | + """Return the number of nodes of a given kind.""" |
| 1611 | + schema = self.schema.get(kind=kind, branch=branch) |
| 1612 | + |
| 1613 | + branch = branch or self.default_branch |
| 1614 | + if at: |
| 1615 | + at = Timestamp(at) |
| 1616 | + |
| 1617 | + response = self.execute_graphql( |
| 1618 | + query=Query(query={schema.kind: {"count": None}}).render(), branch_name=branch, at=at, timeout=timeout |
| 1619 | + ) |
| 1620 | + return int(response.get(schema.kind, {}).get("count", 0)) |
| 1621 | + |
1586 | 1622 | @overload |
1587 | 1623 | def all( |
1588 | 1624 | self, |
@@ -2213,7 +2249,7 @@ def allocate_next_ip_address( |
2213 | 2249 | def allocate_next_ip_address( |
2214 | 2250 | self, |
2215 | 2251 | resource_pool: CoreNodeSync, |
2216 | | - kind: type[SchemaTypeSync] | None = None, # pylint: disable=unused-argument |
| 2252 | + kind: type[SchemaTypeSync] | None = None, # noqa: ARG002 |
2217 | 2253 | identifier: str | None = None, |
2218 | 2254 | prefix_length: int | None = None, |
2219 | 2255 | address_type: str | None = None, |
@@ -2359,7 +2395,7 @@ def allocate_next_ip_prefix( |
2359 | 2395 | def allocate_next_ip_prefix( |
2360 | 2396 | self, |
2361 | 2397 | resource_pool: CoreNodeSync, |
2362 | | - kind: type[SchemaTypeSync] | None = None, # pylint: disable=unused-argument |
| 2398 | + kind: type[SchemaTypeSync] | None = None, # noqa: ARG002 |
2363 | 2399 | identifier: str | None = None, |
2364 | 2400 | prefix_length: int | None = None, |
2365 | 2401 | member_type: str | None = None, |
|
0 commit comments