Skip to content

Commit 305d16a

Browse files
committed
feat(ledger): list_information_block_summaries, the block list as identities and counts
The rows, filters, order and page of list_information_blocks, read by the server in one query instead of an envelope build per block. The call that fills a picker: fact_count > 0 marks a block whose envelope carries facts. The schema snapshot also takes periodRole from robosystems #1832. Waits on the robosystems release carrying #1834.
1 parent ad3d0ea commit 305d16a

9 files changed

Lines changed: 274 additions & 0 deletions

File tree

‎robosystems_client/clients/ledger_client.py‎

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,10 @@
365365
from ..graphql.generated.get_ledger_trial_balance import (
366366
GetLedgerTrialBalanceTrialBalance as TrialBalance,
367367
)
368+
from ..graphql.generated.list_information_block_summaries import (
369+
ListInformationBlockSummaries,
370+
ListInformationBlockSummariesInformationBlockSummaries,
371+
)
368372
from ..graphql.generated.list_information_blocks import (
369373
ListInformationBlocks,
370374
ListInformationBlocksInformationBlocks,
@@ -475,6 +479,7 @@
475479
GET_LEDGER_SUMMARY_GQL,
476480
GET_LEDGER_TRANSACTION_GQL,
477481
GET_LEDGER_TRIAL_BALANCE_GQL,
482+
LIST_INFORMATION_BLOCK_SUMMARIES_GQL,
478483
LIST_INFORMATION_BLOCKS_GQL,
479484
LIST_LEDGER_ACCOUNTS_GQL,
480485
LIST_LEDGER_BLOCKED_SOURCE_GRAPHS_GQL,
@@ -1587,6 +1592,41 @@ def list_information_blocks(
15871592
)
15881593
return ListInformationBlocks.model_validate(data).information_blocks
15891594

1595+
def list_information_block_summaries(
1596+
self,
1597+
graph_id: str,
1598+
*,
1599+
block_type: str | None = None,
1600+
category: str | None = None,
1601+
limit: int | None = None,
1602+
offset: int | None = None,
1603+
scenario_id: str | None = None,
1604+
entity_id: str | None = None,
1605+
) -> list[ListInformationBlockSummariesInformationBlockSummaries]:
1606+
"""List Information Blocks as identities and counts, one row per block.
1607+
1608+
The rows, filters, order and page of ``list_information_blocks``, read
1609+
in one query instead of an envelope build per block — the call that
1610+
fills a picker. ``fact_count > 0`` marks a block whose envelope carries
1611+
facts (a library-seeded structure variant carries none); a block's
1612+
atoms come from ``get_information_block``.
1613+
"""
1614+
data = self._query(
1615+
graph_id,
1616+
LIST_INFORMATION_BLOCK_SUMMARIES_GQL,
1617+
{
1618+
"blockType": block_type,
1619+
"category": category,
1620+
"limit": limit,
1621+
"offset": offset,
1622+
"scenarioId": scenario_id,
1623+
"entityId": entity_id,
1624+
},
1625+
)
1626+
return ListInformationBlockSummaries.model_validate(
1627+
data
1628+
).information_block_summaries
1629+
15901630
def create_information_block(
15911631
self,
15921632
graph_id: str,

‎robosystems_client/graphql/generated/__init__.py‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,10 @@
198198
)
199199
from .get_library_taxonomy import GetLibraryTaxonomy, GetLibraryTaxonomyLibraryTaxonomy
200200
from .list_chart_templates import ListChartTemplates, ListChartTemplatesChartTemplates
201+
from .list_information_block_summaries import (
202+
ListInformationBlockSummaries,
203+
ListInformationBlockSummariesInformationBlockSummaries,
204+
)
201205
from .list_information_blocks import (
202206
ListInformationBlocks,
203207
ListInformationBlocksInformationBlocks,
@@ -380,6 +384,7 @@
380384
GET_LIBRARY_ELEMENT_GQL,
381385
GET_LIBRARY_TAXONOMY_GQL,
382386
LIST_CHART_TEMPLATES_GQL,
387+
LIST_INFORMATION_BLOCK_SUMMARIES_GQL,
383388
LIST_INFORMATION_BLOCKS_GQL,
384389
LIST_INVESTOR_PORTFOLIOS_GQL,
385390
LIST_INVESTOR_POSITIONS_GQL,
@@ -601,6 +606,7 @@
601606
"GraphQLClientInvalidResponseError",
602607
"LIST_CHART_TEMPLATES_GQL",
603608
"LIST_INFORMATION_BLOCKS_GQL",
609+
"LIST_INFORMATION_BLOCK_SUMMARIES_GQL",
604610
"LIST_INVESTOR_PORTFOLIOS_GQL",
605611
"LIST_INVESTOR_POSITIONS_GQL",
606612
"LIST_INVESTOR_SECURITIES_GQL",
@@ -626,6 +632,8 @@
626632
"LIST_LIBRARY_TAXONOMY_ARCS_GQL",
627633
"ListChartTemplates",
628634
"ListChartTemplatesChartTemplates",
635+
"ListInformationBlockSummaries",
636+
"ListInformationBlockSummariesInformationBlockSummaries",
629637
"ListInformationBlocks",
630638
"ListInformationBlocksInformationBlocks",
631639
"ListInformationBlocksInformationBlocksArtifact",

‎robosystems_client/graphql/generated/client.py‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
from .get_library_element_equivalents import GetLibraryElementEquivalents
3838
from .get_library_taxonomy import GetLibraryTaxonomy
3939
from .list_chart_templates import ListChartTemplates
40+
from .list_information_block_summaries import ListInformationBlockSummaries
4041
from .list_information_blocks import ListInformationBlocks
4142
from .list_investor_portfolios import ListInvestorPortfolios
4243
from .list_investor_positions import ListInvestorPositions
@@ -97,6 +98,7 @@
9798
GET_LIBRARY_ELEMENT_GQL,
9899
GET_LIBRARY_TAXONOMY_GQL,
99100
LIST_CHART_TEMPLATES_GQL,
101+
LIST_INFORMATION_BLOCK_SUMMARIES_GQL,
100102
LIST_INFORMATION_BLOCKS_GQL,
101103
LIST_INVESTOR_PORTFOLIOS_GQL,
102104
LIST_INVESTOR_POSITIONS_GQL,
@@ -616,6 +618,33 @@ def list_chart_templates(self, **kwargs: Any) -> ListChartTemplates:
616618
data = self.get_data(response)
617619
return ListChartTemplates.model_validate(data)
618620

621+
def list_information_block_summaries(
622+
self,
623+
block_type: Union[Optional[str], UnsetType] = UNSET,
624+
category: Union[Optional[str], UnsetType] = UNSET,
625+
limit: Union[Optional[int], UnsetType] = UNSET,
626+
offset: Union[Optional[int], UnsetType] = UNSET,
627+
scenario_id: Union[Optional[str], UnsetType] = UNSET,
628+
entity_id: Union[Optional[str], UnsetType] = UNSET,
629+
**kwargs: Any,
630+
) -> ListInformationBlockSummaries:
631+
variables: dict[str, object] = {
632+
"blockType": block_type,
633+
"category": category,
634+
"limit": limit,
635+
"offset": offset,
636+
"scenarioId": scenario_id,
637+
"entityId": entity_id,
638+
}
639+
response = self.execute(
640+
query=LIST_INFORMATION_BLOCK_SUMMARIES_GQL,
641+
operation_name="ListInformationBlockSummaries",
642+
variables=variables,
643+
**kwargs,
644+
)
645+
data = self.get_data(response)
646+
return ListInformationBlockSummaries.model_validate(data)
647+
619648
def list_information_blocks(
620649
self,
621650
block_type: Union[Optional[str], UnsetType] = UNSET,
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
from typing import Optional
2+
3+
from pydantic import Field
4+
5+
from .base_model import BaseModel
6+
7+
8+
class ListInformationBlockSummaries(BaseModel):
9+
information_block_summaries: list[
10+
"ListInformationBlockSummariesInformationBlockSummaries"
11+
] = Field(alias="informationBlockSummaries")
12+
13+
14+
class ListInformationBlockSummariesInformationBlockSummaries(BaseModel):
15+
id: str
16+
block_type: str = Field(alias="blockType")
17+
name: str
18+
display_name: str = Field(alias="displayName")
19+
category: str
20+
taxonomy_id: Optional[str] = Field(alias="taxonomyId")
21+
taxonomy_name: Optional[str] = Field(alias="taxonomyName")
22+
entity_id: Optional[str] = Field(alias="entityId")
23+
fact_count: int = Field(alias="factCount")
24+
connection_count: int = Field(alias="connectionCount")
25+
26+
27+
ListInformationBlockSummaries.model_rebuild()

‎robosystems_client/graphql/generated/operations.py‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
"GET_LIBRARY_TAXONOMY_GQL",
3535
"LIST_CHART_TEMPLATES_GQL",
3636
"LIST_INFORMATION_BLOCKS_GQL",
37+
"LIST_INFORMATION_BLOCK_SUMMARIES_GQL",
3738
"LIST_INVESTOR_PORTFOLIOS_GQL",
3839
"LIST_INVESTOR_POSITIONS_GQL",
3940
"LIST_INVESTOR_SECURITIES_GQL",
@@ -1242,6 +1243,30 @@
12421243
}
12431244
"""
12441245

1246+
LIST_INFORMATION_BLOCK_SUMMARIES_GQL = """
1247+
query ListInformationBlockSummaries($blockType: String, $category: String, $limit: Int, $offset: Int, $scenarioId: String, $entityId: String) {
1248+
informationBlockSummaries(
1249+
blockType: $blockType
1250+
category: $category
1251+
limit: $limit
1252+
offset: $offset
1253+
scenarioId: $scenarioId
1254+
entityId: $entityId
1255+
) {
1256+
id
1257+
blockType
1258+
name
1259+
displayName
1260+
category
1261+
taxonomyId
1262+
taxonomyName
1263+
entityId
1264+
factCount
1265+
connectionCount
1266+
}
1267+
}
1268+
"""
1269+
12451270
LIST_INFORMATION_BLOCKS_GQL = """
12461271
query ListInformationBlocks($blockType: String, $category: String, $limit: Int, $offset: Int, $scenarioId: String, $entityId: String) {
12471272
informationBlocks(
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
query ListInformationBlockSummaries(
2+
$blockType: String
3+
$category: String
4+
$limit: Int
5+
$offset: Int
6+
$scenarioId: String
7+
$entityId: String
8+
) {
9+
informationBlockSummaries(
10+
blockType: $blockType
11+
category: $category
12+
limit: $limit
13+
offset: $offset
14+
scenarioId: $scenarioId
15+
entityId: $entityId
16+
) {
17+
id blockType name displayName category
18+
taxonomyId taxonomyName entityId
19+
factCount connectionCount
20+
}
21+
}

‎robosystems_client/graphql/schema.graphql‎

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -791,6 +791,43 @@ type Query {
791791
entityId: String = null
792792
): [InformationBlock!]!
793793

794+
"""
795+
List Information Blocks as identities and counts, one row per block.
796+
797+
The rows, filters, order and page of `informationBlocks`, read in one
798+
query instead of an envelope build per block — the call that fills a
799+
picker or a rail. `factCount` says whether a block carries facts for
800+
the entity read (a library-seeded structure variant carries none);
801+
a block's atoms come from `informationBlock(id)`.
802+
"""
803+
informationBlockSummaries(
804+
"""Filter to one registered block type, e.g. `schedule`."""
805+
blockType: String = null
806+
807+
"""
808+
Filter on the registry entry's category label, e.g. `Close` or `Reporting`.
809+
"""
810+
category: String = null
811+
812+
"""
813+
Maximum rows to return, 1-1000. Omit to use this field's own default; out of range raises `INVALID_PAGINATION`.
814+
"""
815+
limit: Int = null
816+
817+
"""
818+
Rows to skip before returning, 0 or greater. Out of range raises `INVALID_PAGINATION`.
819+
"""
820+
offset: Int = null
821+
822+
"""
823+
A forecast block's structure id; its entity scopes the list when `entityId` is omitted.
824+
"""
825+
scenarioId: String = null
826+
827+
"""The entity whose blocks and facts to list. Omit for the group parent."""
828+
entityId: String = null
829+
): [InformationBlockSummary!]!
830+
794831
"""Fetch a single Taxonomy Block envelope by id."""
795832
taxonomyBlock(
796833
"""The taxonomy block's structure id."""
@@ -3809,6 +3846,11 @@ type FactRow {
38093846

38103847
"""Indentation depth in the structure hierarchy (0 = root)."""
38113848
depth: Int!
3849+
3850+
"""
3851+
On a roll-forward, `start` for the beginning-balance row and `end` for the ending-balance row — one concept, two rows. Null elsewhere.
3852+
"""
3853+
periodRole: String
38123854
}
38133855

38143856
"""
@@ -3948,6 +3990,44 @@ type BlockedSourceGraph {
39483990
reason: String
39493991
}
39503992

3993+
"""
3994+
One row of a block list: the envelope's identity with counts in place
3995+
of its atoms. Read in one query, so a graph's whole catalogue lists in the
3996+
time one envelope builds.
3997+
"""
3998+
type InformationBlockSummary {
3999+
id: String!
4000+
4001+
"""Discriminator — 'schedule', …"""
4002+
blockType: String!
4003+
name: String!
4004+
4005+
"""Registry-sourced display label (e.g., 'Schedule')."""
4006+
displayName: String!
4007+
4008+
"""Registry-sourced sidebar grouping ('Close', 'Reporting', …)."""
4009+
category: String!
4010+
4011+
"""Source taxonomy the Structure was seeded from."""
4012+
taxonomyId: String
4013+
4014+
"""Display name of the source taxonomy."""
4015+
taxonomyName: String
4016+
4017+
"""
4018+
The entity whose books the block reads: its owner for a schedule, reconciliation or forecast; the entity asked for, else the group parent, on a block shared by the group. Null on the library.
4019+
"""
4020+
entityId: String
4021+
4022+
"""
4023+
Facts in the block's scope for that entity, every set — what its envelope carries. Zero on a library-seeded structure variant and on a schedule that has run off into history, which a picker leaves out.
4024+
"""
4025+
factCount: Int!
4026+
4027+
"""Arcs the block's structure carries."""
4028+
connectionCount: Int!
4029+
}
4030+
39514031
type TaxonomyBlock {
39524032
id: ID!
39534033
name: String!

‎tests/test_facade_wire_shapes.py‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -702,6 +702,22 @@ def test_create_report_sends_the_entity(self, httpx_mock):
702702
body = json.loads(httpx_mock.get_requests()[0].content)
703703
assert body["entity_id"] == "ent_sub"
704704

705+
def test_list_information_block_summaries_sends_filters(self, httpx_mock):
706+
httpx_mock.add_response(
707+
method="POST",
708+
url=f"{BASE}/extensions/{GRAPH}/graphql",
709+
json={"data": {"informationBlockSummaries": []}},
710+
)
711+
712+
blocks = LedgerClient(CONFIG).list_information_block_summaries(
713+
GRAPH, block_type="forecast", entity_id="ent_sub"
714+
)
715+
716+
assert blocks == []
717+
payload = json.loads(httpx_mock.get_requests()[0].content)
718+
assert payload["variables"] == {"blockType": "forecast", "entityId": "ent_sub"}
719+
assert "informationBlockSummaries" in payload["query"]
720+
705721
def test_list_information_blocks_sends_scenario_id(self, httpx_mock):
706722
httpx_mock.add_response(
707723
method="POST",

‎tests/test_ledger_client.py‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1674,6 +1674,34 @@ def test_list_information_blocks(self, mock_execute, mock_config, graph_id):
16741674
variables = mock_execute.call_args[0][2]
16751675
assert variables["blockType"] == "schedule"
16761676

1677+
@patch("robosystems_client.graphql.client.GraphQLClient.execute")
1678+
def test_list_information_block_summaries(self, mock_execute, mock_config, graph_id):
1679+
mock_execute.return_value = {
1680+
"informationBlockSummaries": [
1681+
{
1682+
"id": "str_sched_1",
1683+
"blockType": "schedule",
1684+
"name": "Depreciation",
1685+
"displayName": "Schedule",
1686+
"category": "Close",
1687+
"taxonomyId": "tax_01",
1688+
"taxonomyName": "My CoA",
1689+
"entityId": "ent_parent",
1690+
"factCount": 12,
1691+
"connectionCount": 3,
1692+
}
1693+
]
1694+
}
1695+
client = LedgerClient(mock_config)
1696+
result = client.list_information_block_summaries(graph_id, limit=200)
1697+
assert len(result) == 1
1698+
assert result[0].id == "str_sched_1"
1699+
assert result[0].block_type == "schedule"
1700+
assert (result[0].fact_count, result[0].connection_count) == (12, 3)
1701+
assert not hasattr(result[0], "facts")
1702+
variables = mock_execute.call_args[0][2]
1703+
assert variables["limit"] == 200
1704+
16771705
@patch("robosystems_client.graphql.client.GraphQLClient.execute")
16781706
def test_get_information_block(self, mock_execute, mock_config, graph_id):
16791707
mock_execute.return_value = {

0 commit comments

Comments
 (0)