Repository navigation
fix: expose enum fields as String in where inputs - #397
Closed
bonustrack wants to merge 1 commit into
Closed
bonustrack wants to merge 1 commit into
bonustrack wants to merge 1 commit into
Conversation
Keeps generated filter input shapes stable for clients when an entity field is tightened from String to an enum, matching hub API filter semantics. The output field keeps its enum type. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
bonustrack
force-pushed
the
fix/enum-where-inputs
branch
from
July 11, 2026 15:58
92999f2 to
a920710
Compare
bonustrack
added a commit
to snapshot-labs/sx-monorepo
that referenced
this pull request
Jul 11, 2026
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>
Sekhmet
requested changes
Jul 14, 2026
Member
There was a problem hiding this comment.
Not sure I understand why we want to change it?
With enums we will get correct typing for inputs:
With string we just make it accept anything. I'd imagine that if someone generates their client side query types based on schema they expect it to give them benefit of good types, not as loose as possible.
Maybe there is some benefit to this (I can't find a real benefit from PR description), but it's definitely not a "fix".
I see some reference to ProposalState change than forces us to do it, but I don't see why we don't just do that, clean and type-safe:
diff --git a/apps/ui/src/networks/common/graphqlApi/index.ts b/apps/ui/src/networks/common/graphqlApi/index.ts
index 9545c65bd..e0c26991c 100644
--- a/apps/ui/src/networks/common/graphqlApi/index.ts
+++ b/apps/ui/src/networks/common/graphqlApi/index.ts
@@ -643,30 +643,15 @@ export function createApi(
filters?: ProposalsFilter,
searchQuery = ''
): Promise<Proposal[]> => {
- const _filters: ProposalsFilter = clone(filters || {});
+ const { state, labels, ...restFilters } = filters || {};
const metadataFilters: Record<string, any> = {};
if (searchQuery) metadataFilters.title_contains_nocase = searchQuery;
- const state = _filters.state;
-
- if (state === 'active') {
- _filters.start_lte = current;
- _filters.max_end_gte = current;
- } else if (state === 'pending') {
- _filters.start_gt = current;
- } else if (state === 'closed') {
- _filters.max_end_lt = current;
+ if (labels?.length) {
+ metadataFilters.labels_contains = labels;
}
- delete _filters.state;
-
- if (_filters.labels?.length) {
- metadataFilters.labels_contains = _filters.labels;
- }
-
- delete _filters.labels;
-
const { data } = await apollo.query({
query: PROPOSALS_QUERY,
variables: {
@@ -675,10 +660,11 @@ export function createApi(
where: {
space_in: spaceIds,
cancelled: false,
+ state: state !== 'any' ? state : undefined,
metadata_: Object.keys(metadataFilters).length
? metadataFilters
: undefined,
- ..._filters
+ ...restFilters
}
}
});
Member
|
This has been addressed at consumer side: snapshot-labs/sx-monorepo#2226 |
bonustrack
added a commit
to snapshot-labs/sx-monorepo
that referenced
this pull request
Jul 22, 2026
* feat(api): add computed state field to proposals Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * feat(api): type proposal state as enum Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * fix(ui): keep proposals state filter out of typed where input Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * revert: drop state enum and UI changes, keep state as String 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> * feat(api): restore ProposalState enum for proposal state 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> * revert: keep PR API-only, state as String 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> * feat(api): type proposal state as ProposalState enum 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> * chore: drop checkpoint patch, use released checkpoint once available Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * chore: restore bun.lock from master Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * fix(ui): make proposals state filter type-safe via rest operator 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> --------- Co-authored-by: Claude Fable 5 <noreply@anthropic.com> Co-authored-by: Wan <495709+wa0x6e@users.noreply.github.com> Co-authored-by: Tony <222686154+tony8713@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
When an entity field is typed as a GraphQL enum, the generated
whereinput fields (field,field_not,field_in,field_not_in) are now typed asStringinstead of the enum. The output field keeps its enum type (validation and introspection intact).Why
Consumers that codegen their types from the query schema (e.g. the sx-monorepo UI) construct filter objects in existing code. If tightening an entity field from
Stringto an enum also tightens the filter input, every downstream client is forced to adapt its filter code in lockstep with the schema change. Typing filters asStringkeeps filter shapes stable (and matches hub API filter semantics) while the response side still gets the fully typed enum.Concrete motivation: adding
state: ProposalState! @computedto the sx-monorepo API (snapshot-labs/sx-monorepo#2226) without breaking the UI's regeneratedProposal_filtertypes.Test plan
state: ProposalState!on the type andstate: String/state_not/state_in/state_not_inin the filter input🤖 Generated with Claude Code