Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add beforeOperation.[create|update|delete] and afterOperation.[create|update|delete] operation routing for list hooks #8826

Merged
merged 8 commits into from
Sep 25, 2023
Prev Previous commit
Next Next commit
fix types for runSideEffectOnlyHook
  • Loading branch information
dcousens committed Sep 25, 2023
commit 813bf465c12412169bd8939ca2cf08c5af6b0ded
8 changes: 6 additions & 2 deletions packages/core/src/lib/core/mutations/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,14 @@ import type { InitialisedList } from '../initialise-lists';

export async function runSideEffectOnlyHook<
HookName extends 'beforeOperation' | 'afterOperation',
Args extends Parameters<NonNullable<InitialisedList['hooks'][HookName]>>[0]
Args extends Parameters<
NonNullable<InitialisedList['hooks'][HookName]['create' | 'update' | 'delete']>
>[0]
>(list: InitialisedList, hookName: HookName, args: Args) {
const { operation } = args;

let shouldRunFieldLevelHook: (fieldKey: string) => boolean;
if (args.operation === 'delete') {
if (operation === 'delete') {
// always run field hooks for delete operations
shouldRunFieldLevelHook = () => true;
} else {
Expand Down