Skip to content

fix: use entity field names in CLI delete select instead of PK constraint names#1329

Open
pyramation wants to merge 2 commits into
mainfrom
fix/cli-delete-select-pk-mismatch
Open

fix: use entity field names in CLI delete select instead of PK constraint names#1329
pyramation wants to merge 2 commits into
mainfrom
fix/cli-delete-select-pk-mismatch

Conversation

@pyramation

@pyramation pyramation commented Jul 5, 2026

Copy link
Copy Markdown
Contributor

Summary

The CLI codegen for handleDelete was building the select clause from PK constraint field names (via getPrimaryKeyInfo()), which use PostGraphile's inflected mutation input names. For tables where the inflected PK name differs from the entity field name (e.g. principal table: constraint PK = principalId, entity field = id), the generated select: { principalId: true } fails TypeScript compilation because principalId doesn't exist on PrincipalSelect.

// table-command-generator.ts  — delete select branch
- pkFields.map((pkField) =>
-   t.objectProperty(t.identifier(pkField.name), t.booleanLiteral(true)),
- )
+ pkFields.map((pkField) => {
+   // check entity fields for direct match, then reverse inflection
+   const scalarFields = getScalarFields(table);
+   const direct = scalarFields.find(f => f.name === pkField.name);
+   if (direct) return t.objectProperty(t.identifier(pkField.name), ...);
+   // principalId → strip "principal" prefix → "id" → found in entity fields
+   const prefix = lcFirst(typeName);
+   if (pkField.name.startsWith(prefix)) {
+     const stripped = lcFirst(pkField.name.slice(prefix.length));
+     if (scalarFields.find(f => f.name === stripped))
+       return t.objectProperty(t.identifier(stripped), ...);
+   }
+   return t.objectProperty(t.identifier(pkField.name), ...); // fallback
+ })

Delete select stays minimal (just the PK field) but now resolves the correct entity field name via reverse inflection.

Also fixed the already-generated sdk/constructive-cli/src/auth/cli/commands/principal.ts to unblock CI immediately.

Link to Devin session: https://app.devin.ai/sessions/713a7eeac5ee47abae2dc5a13a23e067
Requested by: @pyramation

…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.
@pyramation pyramation self-assigned this Jul 5, 2026
@devin-ai-integration

Copy link
Copy Markdown
Contributor

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment, CI, and merge conflict monitoring

…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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant