Skip to content

feat(codegen): allow fire-and-forget delete hooks (clientMutationId default)#695

Open
pyramation wants to merge 11 commits intomainfrom
feat/delete-optional-selection
Open

feat(codegen): allow fire-and-forget delete hooks (clientMutationId default)#695
pyramation wants to merge 11 commits intomainfrom
feat/delete-optional-selection

Conversation

@pyramation
Copy link
Contributor

Summary

This PR introduces an optional-selection “fire-and-forget” path for table delete hooks only. When no selection is provided, delete hooks will default to selecting just clientMutationId (a PostGraphile-standard field on CRUD payloads), rather than entity fields.

What changed (scoped to delete hooks):

  • Added a second overload for delete hooks:
    • Overload 1: requires selection.fields (unchanged typed path)
    • Overload 2: no selection; returns { clientMutationId: string } in the payload
  • Implementation now treats selection as optional and uses:
    • select: args.select ?? { clientMutationId: true }
  • Update snapshots for delete hook generation to reflect the new overload and JSDoc
  • No changes to create/update hooks or custom mutations

Rationale:

  • Delete is the cleanest fire-and-forget case: the entity is gone; mutation cache invalidation already removes detail and invalidates lists. Returning clientMutationId communicates that this path intentionally returns no entity data.
  • We do NOT reintroduce “default entity selects” (e.g., { id: true }). This remains removed project-wide.

Files of interest:

  • graphql/codegen/src/core/codegen/mutations.ts (delete hook generator)
  • graphql/codegen/src/tests/codegen/snapshots/react-query-hooks.test.ts.snap (updated snapshots)

Note: This PR is based off the latest remove-default-selects branch. It will include its already-reviewed diffs (workflows path ignores, makage bump, etc.) when merged into main.

Review & Testing Checklist for Human (3–5 items)

  • Verify generated delete hooks for a few tables:
    • Overload 1 signature still requires selection.fields and returns typed entity payload
    • Overload 2 signature is selection-optional and its return type is { clientMutationId: string }
    • JSDoc text reflects both paths
  • Inspect the generated mutation function body for delete:
    • Ensures select: args.select ?? { clientMutationId: true }
    • Query invalidation behavior unchanged: removes detail and invalidates lists
  • Confirm no ripple effects:
    • Create/update hooks remain unchanged (selection still required)
    • Custom mutations remain unchanged (no assumption of clientMutationId)
    • No reintroduction of “default entity selects” anywhere
  • Type-check/compile a generated project to ensure the new overloads are consumable in TS without regressions (especially with centralized mutation keys on/off)
  • Sanity-run codegen on the example schema and scan output for delete hooks to ensure only delete hooks gained the new behavior

Recommended manual test plan:

  1. From repo root: pnpm build
  2. In graphql/codegen: pnpm test (should be all green; 3 snapshots updated relative to previous behavior)
  3. Run codegen against the example schema or a PostGraphile app; inspect mutations/useDelete*Mutation.ts outputs for:
    • The two overloads
    • Optional selection in the implementation signature
    • Fallback select using { clientMutationId: true }

Notes

yyyyaaa and others added 11 commits February 6, 2026 01:59
…copy patterns

- Convert queries.ts, mutations.ts, custom-queries.ts, custom-mutations.ts from lines.push() string concatenation to Babel AST generation
- Convert client.ts and selection.ts from string template literals to template-copy pattern
- Add hooks-ast.ts shared helper library for Babel AST node construction
- Add template files: hooks-client.ts, hooks-selection.ts
- Add AGENTS.md with codegen rules (AST-only, no string concat, templates as files)
- Update test snapshots for Babel formatting changes (whitespace/formatting only)
…-browser-compatible

- Add hyphenateKeys, flattenDbFields, buildDbConfig, seedArgvFromConfig,
  buildGenerateOptions to shared.ts as generic reusable utilities
- Replace manual cliOverrides/hasNonInteractiveArgs with prompt->camelize->generate flow
- Remove deprecated --browser-compatible flag from CLI, config types, and generate
- Simplify both CLI entry points (graphql/codegen/src/cli, packages/cli)
- Update test mocks to match new shared utility imports
- Remove all defaultSelect constants and overload 2 (without fields) from all hook generators
- Remove buildDefaultSelectExpr, buildSelectFallbackExpr, buildDefaultSelectLiteral, getDefaultSelectFieldName
- Remove withoutFieldsSelectionType, withoutFieldsListSelectionType, NON_SELECT_TYPES_AST
- Remove buildDefaultSelectExpression from ORM custom-ops-generator
- Remove defaultSelect/defaultRef from ORM model-generator
- Make selection with fields required in all hook and ORM method signatures
- Update 25 snapshots to reflect removed overloads
@devin-ai-integration
Copy link
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

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.

2 participants