Repository navigation
feat(api): add computed state field to proposals - #2226
Conversation
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Enum type in the API schema forces regenerated UI filter types to reject the UI's existing state values, requiring UI changes. Keep state as a String so this PR stays API-only. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
The enum tightens the codegen'd UI filter types, so the UI filter construction is adjusted type-only (destructure instead of delete). No UI runtime behavior or query changes. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
The ProposalState enum will come in a follow-up PR together with the UI adopting server-side state filtering, after the API is deployed. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Filters stay String-typed so codegen'd client filter shapes are unaffected, via a temporary patch of checkpoint (snapshot-labs/checkpoint#397). Remove the patch and bump checkpoint once it is released. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Sekhmet
left a comment
There was a problem hiding this comment.
Changes there look good to me, I don't think we need changes in Checkpoint (and it's better if we keep those as is) and instead make types actually work properly here (types are not being updated via delete, we can use rest operator to handle that:
diff --git a/apps/ui/src/networks/common/graphqlApi/index.ts b/apps/ui/src/networks/common/graphqlApi/index.ts
index 9545c65bd..32b7243a5 100644
--- a/apps/ui/src/networks/common/graphqlApi/index.ts
+++ b/apps/ui/src/networks/common/graphqlApi/index.ts
@@ -643,30 +643,30 @@ export function createApi(
filters?: ProposalsFilter,
searchQuery = ''
): Promise<Proposal[]> => {
- const _filters: ProposalsFilter = clone(filters || {});
+ const {
+ state: stateFilter,
+ labels,
+ ...restFilters
+ }: ProposalsFilter = filters || {};
const metadataFilters: Record<string, any> = {};
if (searchQuery) metadataFilters.title_contains_nocase = searchQuery;
- const state = _filters.state;
+ const state = stateFilter;
if (state === 'active') {
- _filters.start_lte = current;
- _filters.max_end_gte = current;
+ restFilters.start_lte = current;
+ restFilters.max_end_gte = current;
} else if (state === 'pending') {
- _filters.start_gt = current;
+ restFilters.start_gt = current;
} else if (state === 'closed') {
- _filters.max_end_lt = current;
+ restFilters.max_end_lt = current;
}
- delete _filters.state;
-
- if (_filters.labels?.length) {
- metadataFilters.labels_contains = _filters.labels;
+ if (labels?.length) {
+ metadataFilters.labels_contains = labels;
}
- delete _filters.labels;
-
const { data } = await apollo.query({
query: PROPOSALS_QUERY,
variables: {
@@ -678,7 +678,7 @@ export function createApi(
metadata_: Object.keys(metadataFilters).length
? metadataFilters
: undefined,
- ..._filters
+ ...restFilters
}
}
});
Here we use the same query, just updating our code to be type-safe. Once API is updated we can simplify it further to actually use state from filter directly (dropping any).
Destructure state/labels out of the filters instead of clone + delete so the spread into Proposal_filter no longer carries the enum-incompatible 'any' state value. Keeps the checkpoint-generated enum filters as-is. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
|
Good call, dropped the Checkpoint dependency entirely. Applied your rest-operator refactor to Verified locally against a freshly generated schema (current released Checkpoint, no patch): regenerated |
Summary
Adds a
statefield toProposalon the SX-API, computed at query time from the voting window timestamps and typed as aProposalStateenum:pending: voting has not started yet (startis in the future)active: voting window is openclosed: pastmax_endThis mirrors the hub API's
statefield so consumers can read the proposal lifecycle the same way from both APIs. It uses the same@computedSQL resolver mechanism asSpace.active_proposal_count: the state is computed inside the SQL query (aCASEoverstart/max_endvsnow()), so there is no new column, no reindex, and no writer changes. Values update live as time passes without any writes.No visual UI changes. The response field is enum-typed, and the enum filters Checkpoint generates for it are handled type-safely in the UI:
loadProposalsdestructuresstate/labelsout of the filter and spreads only the rest intoProposal_filter, so the UI keeps translatingstateinto the existing timestamp filters (start_lte,max_end_gte, etc.) and sends byte-identical queries. No Checkpoint changes needed.How to test
Run the API locally against any populated database (
IS_INDEXER=false bun run devinapps/api), then:Read the field (enum-typed in responses and introspection):
{ proposals(indexer: "eth", orderBy: created, orderDirection: desc, first: 10) { id start max_end state } } { __type(name: "ProposalState") { enumValues { name } } }Filter with where:
{ proposals(indexer: "eth", where: { state: active }) { id state } } { proposals(indexer: "eth", where: { state_in: [pending, active] }) { id state } } { proposals(indexer: "eth", where: { state_not: closed }) { id state } }Order by state:
{ proposals(indexer: "eth", orderBy: state, orderDirection: asc) { id state } }Single and nested paths (resolved through the DataLoader):
{ proposal(id: "<proposal-id>", indexer: "eth") { id state } } { spaces(indexer: "eth", first: 5) { id proposals { id state } } }Test plan
tsc, eslint and vitest pass on the APIvue-tsc --noEmitpasses clean. The previous clone+delete filter code errored (Type '"any"' is not assignable to type 'InputMaybe<ProposalState>'); the rest-operator version fixes it.pending->activelive as its start time passedNote on CI
The
getSpaceControllershib test fails becausestamp.fyi'sget_ownerfor Shibarium returns500 unauthorized(D3 partner API rejectingD3_API_KEY_MAINNET). Fails identically on master's code, not caused by this diff.🤖 Generated with Claude Code