Skip to content

feat: codegen support for bulk mutations (Phase 6)#1148

Merged
pyramation merged 2 commits into
mainfrom
feat/bulk-mutations-codegen
May 13, 2026
Merged

feat: codegen support for bulk mutations (Phase 6)#1148
pyramation merged 2 commits into
mainfrom
feat/bulk-mutations-codegen

Conversation

@pyramation
Copy link
Copy Markdown
Contributor

Summary

Phase 6 of the bulk mutations feature: extends the codegen pipeline to generate ORM methods, React Query mutation hooks, and CLI commands for the bulk mutations exposed by the graphile-bulk-mutations plugin (Phases 1-4) and integrated via enable_bulk database settings (Phase 5).

Changes

Introspection (graphql/query)

  • Extended TableQueryNames interface with bulkInsert, bulkUpsert, bulkUpdate, bulkDelete fields
  • Extended matchMutationOperations() to detect bulkCreate{Plural}, bulkUpsert{Plural}, etc. from the schema
  • Extended getTableOperationNames() to include bulk mutations in the exclusion set (prevents them from being treated as custom operations)

Templates (graphql/codegen/src/core/codegen/templates/)

  • query-builder.ts: Added buildBulkInsertDocument, buildBulkUpsertDocument, buildBulkUpdateDocument, buildBulkDeleteDocument functions
  • select-types.ts: Added BulkInsertArgs, BulkUpsertArgs, BulkUpdateArgs, BulkDeleteArgs, and BulkMutationResult types

ORM Model Generation (model-generator.ts)

  • Generates bulkCreate(), bulkUpsert(), bulkUpdate(), bulkDelete() class methods when the table has the corresponding bulk mutations
  • Returns QueryBuilder<BulkMutationResult<InferSelectResult<T, S>>>

React Query Hooks (mutations.ts)

  • Generates useBulkCreate{Type}Mutation, useBulkUpsert{Type}Mutation, useBulkUpdate{Type}Mutation, useBulkDelete{Type}Mutation hooks
  • Includes proper query key invalidation (invalidates list queries on success)
  • Adds bulk mutation keys to mutation-keys.ts

CLI Commands (table-command-generator.ts)

  • Generates bulk-create, bulk-upsert, bulk-update, bulk-delete subcommands
  • bulk-create/upsert accept --data (JSON array), bulk-update accepts --where + --data, bulk-delete accepts --where

Utils

  • Added bulk naming helpers: getBulkCreateMutationHookName, getBulkCreateMutationFileName, etc.

Review & Testing Checklist for Human

  • Run codegen against a schema with enable_bulk enabled and tables tagged with @behavior +bulkInsert +bulkUpsert +bulkUpdate +bulkDelete — verify generated ORM model has bulk methods
  • Verify generated React Query hooks compile and are properly typed (data arrays, where clauses, BulkMutationResult return type)
  • Verify generated CLI commands appear in the subcommand list and accept the expected flags
  • Check that tables WITHOUT bulk smart tags produce NO bulk methods/hooks/commands (opt-in only)

Notes

  • All code generation uses Babel AST per the AGENTS.md rules — no string concatenation
  • Builds and typechecks clean (tsc --noEmit passes)
  • Bulk hooks follow the same patterns as existing create/update/delete hooks for consistency
  • The bulk CLI commands use JSON input (since they deal with arrays/objects) rather than interactive prompting

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

…y hooks, CLI commands)

Phase 6 of the bulk mutations feature:

- Extend introspection to detect bulkCreate/bulkUpsert/bulkUpdate/bulkDelete
  mutations from the GraphQL schema (infer-tables.ts, transform-schema.ts)
- Add bulk document builders to query-builder template
  (buildBulkInsertDocument, buildBulkUpsertDocument, etc.)
- Add bulk arg types and BulkMutationResult to select-types template
- Generate ORM bulk methods on model classes (bulkCreate, bulkUpsert,
  bulkUpdate, bulkDelete) via Babel AST in model-generator.ts
- Generate React Query mutation hooks (useBulkCreateX, useBulkUpsertX,
  useBulkUpdateX, useBulkDeleteX) in mutations.ts
- Generate CLI subcommands (bulk-create, bulk-upsert, bulk-update,
  bulk-delete) in table-command-generator.ts
- Add bulk mutation keys to mutation-keys.ts for tracking in-flight
  mutations
- Add bulk naming helper functions to utils.ts
@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 and CI monitoring

@pyramation pyramation merged commit f53de30 into main May 13, 2026
38 checks passed
@pyramation pyramation deleted the feat/bulk-mutations-codegen branch May 13, 2026 06:23
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