feat: codegen support for bulk mutations (Phase 6)#1148
Merged
Conversation
…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
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:
|
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
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-mutationsplugin (Phases 1-4) and integrated viaenable_bulkdatabase settings (Phase 5).Changes
Introspection (
graphql/query)TableQueryNamesinterface withbulkInsert,bulkUpsert,bulkUpdate,bulkDeletefieldsmatchMutationOperations()to detectbulkCreate{Plural},bulkUpsert{Plural}, etc. from the schemagetTableOperationNames()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: AddedbuildBulkInsertDocument,buildBulkUpsertDocument,buildBulkUpdateDocument,buildBulkDeleteDocumentfunctionsselect-types.ts: AddedBulkInsertArgs,BulkUpsertArgs,BulkUpdateArgs,BulkDeleteArgs, andBulkMutationResulttypesORM Model Generation (
model-generator.ts)bulkCreate(),bulkUpsert(),bulkUpdate(),bulkDelete()class methods when the table has the corresponding bulk mutationsQueryBuilder<BulkMutationResult<InferSelectResult<T, S>>>React Query Hooks (
mutations.ts)useBulkCreate{Type}Mutation,useBulkUpsert{Type}Mutation,useBulkUpdate{Type}Mutation,useBulkDelete{Type}Mutationhooksmutation-keys.tsCLI Commands (
table-command-generator.ts)bulk-create,bulk-upsert,bulk-update,bulk-deletesubcommands--data(JSON array), bulk-update accepts--where+--data, bulk-delete accepts--whereUtils
getBulkCreateMutationHookName,getBulkCreateMutationFileName, etc.Review & Testing Checklist for Human
enable_bulkenabled and tables tagged with@behavior +bulkInsert +bulkUpsert +bulkUpdate +bulkDelete— verify generated ORM model has bulk methodsNotes
tsc --noEmitpasses)Link to Devin session: https://app.devin.ai/sessions/b5701e74c8b44bbf89db370f3323acf2
Requested by: @pyramation