Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const { Relationship } = require('@keystonejs/fields');
// Set up a fresh mutation state if we're the root mutation
const isRootMutation = !mutationState;
if (isRootMutation) {
mutationState = {
afterChangeStack: [], // post-hook stack
queues: {}, // backlink queues
transaction: {}, // transaction
};
}
// Perform the mutation
const { result, afterHook } = await mutation(mutationState);
// resolve backlinks
await Relationship.resolveBacklinks(context, mutationState);
// Push after-hook onto the stack and resolve all if we're the root.
const { afterChangeStack } = mutationState;
afterChangeStack.push(afterHook);
if (isRootMutation) {
// TODO: Close transaction
// Execute post-hook stack
while (afterChangeStack.length) {
await afterChangeStack.pop()();
}
}
// Return the result of the mutation
return result;
}