fix: distinguish custom SQL function mutations from CRUD in codegen#1329
Merged
Conversation
…aint names The codegen for CLI delete handlers was using PK constraint field names (e.g. principalId) in the select clause, but these names come from PostGraphile's inflected mutation input names and may differ from the entity's actual field names (e.g. id) in the Select type. Use buildSelectObject() for delete (same as create/update) to ensure select uses entity field names that match the generated Select types.
Contributor
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
…g all fields Map PK constraint names back to entity field names via reverse inflection (e.g. principalId → id) so delete select stays minimal while using correct field names that exist on the generated *Select type.
matchMutationOperations now checks the payload type before claiming a mutation as CRUD. PostGraphile CRUD payloads always contain a field named lcFirst(entityName) whose type is the entity (e.g. DeleteUserPayload has `user: User`). Custom SQL-function mutations that happen to follow the same naming convention (e.g. `deletePrincipal`) return something else — typically `result: Boolean` — and are no longer mistaken for CRUD. This fixes Principal, whose delete/create are custom SQL functions (`delete_principal()`, `create_principal()`) that PostGraphile exposes as `deletePrincipal` / `createPrincipal`. The codegen was treating these as standard CRUD mutations, which caused a TS error because the inferred PK constraint name (`principalId`, from the function arg) did not match the entity field name (`id`) in PrincipalSelect. Reverts the earlier reverse-inflection workaround in table-command-generator.ts — the root cause is now fixed upstream in infer-tables.ts.
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
matchMutationOperationsininfer-tables.tsmatched mutations purely by naming convention (delete{EntityName},create{EntityName}). Custom SQL functions likedelete_principal()/create_principal()are exposed by PostGraphile asdeletePrincipal/createPrincipal— identical to CRUD naming — and were incorrectly claimed as CRUD mutations.For
Principal, the codegen then inferred PK constraints fromDeletePrincipalInput { principalId: UUID }(the SQL function arg), producedselect: { principalId: true }in the CLI delete handler, butPrincipalSelectonly hasid→ TS error.Fix:
matchMutationOperationsnow checks the payload type before claiming a mutation as CRUD:Applied to all three CRUD checks (create/update/delete) and their
ById/By*variants.Reverts the earlier reverse-inflection workaround in
table-command-generator.ts— the delete select logic is restored to the originalpkFields.map(f => f.name: true)since PK constraint names now always come from real CRUD mutations where they match entity field names.Generated
principal.ts: no longer hashandleDeleteorhandleGet(no CRUD delete/update). Commands:list,find-first,create.Link to Devin session: https://app.devin.ai/sessions/713a7eeac5ee47abae2dc5a13a23e067
Requested by: @pyramation