Repository navigation
feat: add @computed directive and custom resolvers - #390
Merged
Merged
Conversation
Fields marked with @computed are resolved at query time via user-provided resolver functions instead of being backed by a database column. - Add @computed directive (skipped from DB table creation, codegen, where filters, and orderBy) - Add `resolvers` option to CheckpointOptions for registering custom field resolvers per entity type - Merge custom resolvers into the auto-generated GraphQL schema Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This was referenced May 26, 2026
Computed resolvers can now provide a `sql` function alongside `resolve`. When present, the subquery is added to SELECT and used for ORDER BY without the table prefix, enabling database-level sorting and pagination on computed fields. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Drop the function-only shorthand. Always require { sql } config.
resolve is optional and auto-falls back to the sql subselect result
from list queries or 0 for single-entity queries.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Computed Int fields now support the full set of where operators: equals, _not, _gt, _gte, _lt, _lte, _in, _not_in. Also simplifies the where filter generation and resolver handling. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Sekhmet
reviewed
Jun 25, 2026
Address PR review: - Drop the dual resolve/sql config; sql is the only way to define a computed field. DataLoader now adds the same subselect, so single- entity and nested queries get the value via standard GraphQL field resolution from the parent row (no separate resolver needed). - Drop the Int-only restriction on where filters. Computed fields now fall through the normal field processing and receive the full set of type-appropriate filters (Int gt/lt/in/..., String contains/..., etc.) with the same suffixes supported in handleWhere via subquery. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
- Collapse getDerivedFromDirective/getComputedDirective into a single parameterized getDirective helper - Extract directiveDef/nonNullStringArg factories in extendSchema - Merge LIKE/ILIKE operators into a map alongside the comparison ops - Extract getComputedConfigs helper shared by queryMulti and the DataLoader (case-insensitive type-name lookup) No behavior change. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Sekhmet
reviewed
Jun 26, 2026
Sekhmet
reviewed
Jun 26, 2026
Sekhmet
reviewed
Jun 26, 2026
Sekhmet
enabled auto-merge (squash)
June 29, 2026 15:34
tony8713
pushed a commit
to snapshot-labs/sx-monorepo
that referenced
this pull request
Jun 29, 2026
Add active_proposal_count as a @computed field on Space in the API, resolved at query time by counting proposals where start <= now and max_end > now. Display the active count in the explore page for all protocols and sort onchain spaces by active proposals. Depends on snapshot-labs/checkpoint#390 Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Sekhmet
pushed a commit
to snapshot-labs/sx-monorepo
that referenced
this pull request
Jun 29, 2026
* feat: show active proposals count for Snapshot X and Governor spaces Add active_proposal_count as a @computed field on Space in the API, resolved at query time by counting proposals where start <= now and max_end > now. Display the active count in the explore page for all protocols and sort onchain spaces by active proposals. Depends on snapshot-labs/checkpoint#390 Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * fix: correct resolver table name, add sql subquery for sorting - Fix resolver to query the shared `proposals` table with `_indexer` filter instead of a non-existent `{indexer}_proposals` table - Provide `sql` subquery so active_proposal_count can be used in ORDER BY at the database level (enables proper pagination) - Remove client-side sort, use orderBy: active_proposal_count in the GraphQL query instead Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * refactor: simplify resolver to sql-only config Drop the redundant resolve function, only provide the sql subquery. Checkpoint auto-derives field resolution from the sql subselect result. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * refactor: drop UI changes from this PR (split to stacked UI PR) Revert the 4 apps/ui files to base so #2125 contains only the backend/API active_proposal_count changes. The UI half (Explore column + graphqlApi queries) moves to a stacked UI PR. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * chore(api): bump checkpoint to 0.1.0-beta.73 for @computed support Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * style(api): fix prettier formatting in active_proposal_count resolver Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com> Co-authored-by: Tony <222686154+tony8713@users.noreply.github.com>
Sekhmet
pushed a commit
to snapshot-labs/sx-monorepo
that referenced
this pull request
Jul 3, 2026
* feat: show active proposals count for Snapshot X and Governor spaces Add active_proposal_count as a @computed field on Space in the API, resolved at query time by counting proposals where start <= now and max_end > now. Display the active count in the explore page for all protocols and sort onchain spaces by active proposals. Depends on snapshot-labs/checkpoint#390 Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * fix: correct resolver table name, add sql subquery for sorting - Fix resolver to query the shared `proposals` table with `_indexer` filter instead of a non-existent `{indexer}_proposals` table - Provide `sql` subquery so active_proposal_count can be used in ORDER BY at the database level (enables proper pagination) - Remove client-side sort, use orderBy: active_proposal_count in the GraphQL query instead Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * refactor: simplify resolver to sql-only config Drop the redundant resolve function, only provide the sql subquery. Checkpoint auto-derives field resolution from the sql subselect result. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * refactor: drop UI changes from this PR (split to stacked UI PR) Revert the 4 apps/ui files to base so #2125 contains only the backend/API active_proposal_count changes. The UI half (Explore column + graphqlApi queries) moves to a stacked UI PR. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * feat(ui): add active proposals Explore column UI half split out of #2125. Adds the Active column to the Explore view and the active_proposal_count wiring in graphqlApi queries. Stacked on the backend PR #2125. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * revert(ui): keep Explore sort by vote_count Ordering by active_proposal_count falls back to effectively random order for spaces with no active proposals. Revert the Spaces query ordering to vote_count as before, while keeping the active proposals column. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> --------- Co-authored-by: Less <fabien@bonustrack.co> Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com> Co-authored-by: Tony <222686154+tony8713@users.noreply.github.com> Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: Wan <495709+wa0x6e@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds a
@computeddirective for schema fields resolved at query time via custom SQL subqueries instead of database columns.sqlfunction returning a Knex subquery@computedfields are skipped from DB table creation and codegen@computedfields support the full set oforderByandwhereoperators based on the underlying type (numeric comparisons, string contains, in/not_in, etc.)queryMulti) and single-entity (DataLoader) queries, so the value is available everywhere via standard GraphQL field resolutionUsage
Schema:
Checkpoint init:
Queries:
Test plan
@computedfields excluded from generated DB tables@computedfields excluded from codegen models@computedfields included in orderBy enum and where filters (full type-appropriate set)🤖 Generated with Claude Code