-
-
Notifications
You must be signed in to change notification settings - Fork 12
Open
Description
Is there a reliable way to infer the proper return type of loadAfterMutationEntities and loadBeforeMutationEntities?
zenstack-v3/packages/runtime/src/client/plugin.ts
Lines 170 to 174 in 35a9e0d
| /** | |
| * Loads the entities that have been mutated. | |
| */ | |
| loadAfterMutationEntities(): Promise<Record<string, unknown>[] | undefined>; | |
zenstack-v3/packages/runtime/src/client/plugin.ts
Lines 153 to 158 in 35a9e0d
| /** | |
| * Loads the entities that are about to be mutated. The db operation that loads the entities is executed | |
| * within the same transaction context as the mutation. | |
| */ | |
| loadBeforeMutationEntities(): Promise<Record<string, unknown>[] | undefined>; | |
If the return data is typed, it becomes easier working with any follow up queries:
export const onAfterPostDelete = definePlugin<SchemaType>({
id: "onAfterPostDelete",
onEntityMutation: {
async beforeEntityMutation({ model, action, loadBeforeMutationEntities, client, queryId }) {
const deletedPost = await loadBeforeMutationEntities() // <--- typed as Record<string, unknown>[] | undefined but its really a Post[]
if (action === "delete" && model === "Post") {
// Do some logic
const tags = await client.tag.findMany({
where: {
postId: deletedPost[0].id, // <-- This doesn't work unless we cast deletedPost to proper type like Post[]
},
})
}
},
},
})Metadata
Metadata
Assignees
Labels
No labels