-
Notifications
You must be signed in to change notification settings - Fork 50
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
Update data in field pre hook #123
Comments
Hi @grimabe, pre: (next, root, args, ...rest) => {
// replace with hashed password
args.password = hash(args.password)
next(root, args, ...rest)
} Give it a try and let me know if it worked or not! |
Hi @tothandras, Do you have something else to try ? |
Hi @grimabe, const hooks = {
mutation: {
pre(next, args, context, info) {
if (info.fieldName === 'updateUser') {
args.name += ' MutationPreHook';
}
next(args, context, info);
}
}
};
const schema = getSchema([User], { hooks }); Let's see a user:
Update its name:
|
In my user model I have a password field that I would like to hash when the user is created or updated.
I already achieve to do it with mongoose pre save hook.
But it appears to be only working when creating the document because the update mutation doesn't seems to use the model save method.
So I thought about using the field pre hook like below but I don't know how to update the value.
Is there a way to do that ?
Thank you
The text was updated successfully, but these errors were encountered: