Skip to content

fix(codegen): include partition keys in ORM update/delete mutations#1295

Merged
pyramation merged 1 commit into
mainfrom
feat/codegen-partition-keys
Jun 14, 2026
Merged

fix(codegen): include partition keys in ORM update/delete mutations#1295
pyramation merged 1 commit into
mainfrom
feat/codegen-partition-keys

Conversation

@pyramation

Copy link
Copy Markdown
Contributor

Summary

PostGraphile adds extra required fields to update/delete mutation inputs for partitioned tables (e.g. databaseId as partition key). The ORM codegen was only emitting { id, patch } for updates and { id } for deletes, causing runtime GraphQL validation errors:

GraphQL Error: Variable "$input" got invalid value { id: "...", platformFunctionGraphRefPatch: { commitId: "..." } };
Field "databaseId" of required type "UUID!" was not provided.

Fix: At codegen time, introspect UpdateXxxInput / DeleteXxxInput types via typeRegistry to discover required fields beyond clientMutationId + PK + patch. These "extra keys" (e.g. databaseId) are:

  1. Added to the where type so callers must provide them:

    // before: where: { id: string }
    // after:  where: { id: string; databaseId: string }
  2. Included in the runtime mutation variables via a new extraKeys param on buildUpdateByPkDocument:

    variables: { input: { [idFieldName]: id, ...extraKeys, [patchFieldName]: data } }

For buildDeleteByPkDocument, extra keys are merged into the existing keys object (already a Record<string, unknown>).

When typeRegistry is unavailable (e.g. file-based codegen without introspection), behavior is unchanged — no extra keys are discovered.

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

PostGraphile adds extra required fields (e.g. databaseId) to the
update/delete mutation inputs for partitioned tables. The ORM codegen
was only emitting { id, patch } for updates and { id } for deletes,
causing GraphQL validation errors at runtime.

Changes:
- query-builder template: buildUpdateByPkDocument accepts optional
  extraKeys param, spread into the input variables
- model-generator: introspects UpdateInput/DeleteInput types via
  typeRegistry to discover extra required fields beyond PK + patch
- Extra keys are added to the where type (TypeScript) and included
  in the runtime mutation variables
- generateAllModelFiles now receives typeRegistry from orchestrator
@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

@pyramation pyramation merged commit ee8631e into main Jun 14, 2026
37 checks passed
@pyramation pyramation deleted the feat/codegen-partition-keys branch June 14, 2026 06:06
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