|
29 | 29 | from ..api.extensions_robo_ledger.op_auto_map_elements import ( |
30 | 30 | sync_detailed as op_auto_map_elements, |
31 | 31 | ) |
| 32 | +from ..api.extensions_robo_ledger.op_build_fact_grid import ( |
| 33 | + sync_detailed as op_build_fact_grid, |
| 34 | +) |
32 | 35 | from ..api.extensions_robo_ledger.op_close_period import ( |
33 | 36 | sync_detailed as op_close_period, |
34 | 37 | ) |
|
69 | 72 | sync_detailed as op_update_entity, |
70 | 73 | ) |
71 | 74 | from ..client import AuthenticatedClient |
72 | | -from ..graphql.client import GraphQLClient |
| 75 | +from ..graphql.client import GraphQLClient, strip_none_vars |
73 | 76 | from ..graphql.queries.ledger import ( |
74 | 77 | GET_ACCOUNT_ROLLUPS_QUERY, |
75 | 78 | GET_ACCOUNT_TREE_QUERY, |
|
123 | 126 | from ..models.auto_map_elements_operation import AutoMapElementsOperation |
124 | 127 | from ..models.close_period_operation import ClosePeriodOperation |
125 | 128 | from ..models.create_closing_entry_operation import CreateClosingEntryOperation |
| 129 | +from ..models.create_view_request import CreateViewRequest |
126 | 130 | from ..models.create_manual_closing_entry_request import CreateManualClosingEntryRequest |
127 | 131 | from ..models.create_manual_closing_entry_request_entry_type import ( |
128 | 132 | CreateManualClosingEntryRequestEntryType, |
@@ -204,8 +208,15 @@ def _query( |
204 | 208 | query: str, |
205 | 209 | variables: dict[str, Any] | None = None, |
206 | 210 | ) -> dict[str, Any]: |
207 | | - """Execute a read against the per-graph GraphQL endpoint.""" |
208 | | - return self._get_graphql_client().execute(graph_id, query, variables) |
| 211 | + """Execute a read against the per-graph GraphQL endpoint. |
| 212 | +
|
| 213 | + ``None`` values in ``variables`` are stripped before sending — the |
| 214 | + facade takes ``None`` to mean "not provided", and some Strawberry |
| 215 | + resolvers treat an explicit ``null`` differently from an unset arg. |
| 216 | + See ``strip_none_vars`` in ``graphql/client.py``. |
| 217 | + """ |
| 218 | + cleaned = strip_none_vars(variables) if variables else None |
| 219 | + return self._get_graphql_client().execute(graph_id, query, cleaned) |
209 | 220 |
|
210 | 221 | def _unwrap(self, label: str, envelope: OperationEnvelope | Any) -> Any: |
211 | 222 | """Unwrap an operation envelope and return `result` (None on failure).""" |
@@ -515,7 +526,7 @@ def delete_mapping_association( |
515 | 526 | graph_id=graph_id, body=body, client=self._get_client() |
516 | 527 | ) |
517 | 528 | envelope = self._call_op("Delete mapping association", response) |
518 | | - return envelope.result or {"deleted": True} |
| 529 | + return envelope.result if envelope.result is not None else {"deleted": True} |
519 | 530 |
|
520 | 531 | def auto_map_elements(self, graph_id: str, mapping_id: str) -> dict[str, Any]: |
521 | 532 | """Trigger the AI MappingAgent (async). Returns an operation ack.""" |
@@ -714,6 +725,33 @@ def create_manual_closing_entry( |
714 | 725 | envelope = self._call_op("Create manual closing entry", response) |
715 | 726 | return envelope.result or {} |
716 | 727 |
|
| 728 | + # ── Fact grid (graph-backed analytical query) ───────────────────── |
| 729 | + |
| 730 | + def build_fact_grid(self, graph_id: str, request: dict[str, Any]) -> dict[str, Any]: |
| 731 | + """Build a multi-dimensional fact grid against the graph schema. |
| 732 | +
|
| 733 | + This is a graph-database *read* dispatched through the operation |
| 734 | + surface — it runs against LadybugDB (not the extensions OLTP |
| 735 | + database) and returns a deduplicated pivot table of XBRL facts. |
| 736 | + The same operation works for roboledger tenant graphs (after |
| 737 | + materialization) and for the SEC shared repository, which uses the |
| 738 | + same hypercube schema. |
| 739 | +
|
| 740 | + ``request`` accepts any fields of |
| 741 | + ``robosystems_client.models.create_view_request.CreateViewRequest``: |
| 742 | + ``elements`` (qnames), ``canonical_concepts``, ``periods``, |
| 743 | + ``entities``, ``form``, ``fiscal_year``, ``fiscal_period``, |
| 744 | + ``period_type``, ``include_summary``, ``view_config``. The legacy |
| 745 | + model name ``CreateViewRequest`` is a holdover from when fact grids |
| 746 | + were exposed under a ``/views`` route; the shape is unchanged. |
| 747 | + """ |
| 748 | + body = CreateViewRequest.from_dict(request) |
| 749 | + response = op_build_fact_grid( |
| 750 | + graph_id=graph_id, body=body, client=self._get_client() |
| 751 | + ) |
| 752 | + envelope = self._call_op("Build fact grid", response) |
| 753 | + return envelope.result or {} |
| 754 | + |
717 | 755 | # ── Closing book ─────────────────────────────────────────────────── |
718 | 756 |
|
719 | 757 | def get_closing_book_structures(self, graph_id: str) -> dict[str, Any] | None: |
|
0 commit comments