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

How can i perform some task after mutation #250

Open
gvvsriram opened this issue May 18, 2020 · 2 comments
Open

How can i perform some task after mutation #250

gvvsriram opened this issue May 18, 2020 · 2 comments

Comments

@gvvsriram
Copy link

For example, if i need to send an email after a user has signed up how can i do i see a pre-save hook but didn't find any for the post.

@nodkz
Copy link
Member

nodkz commented May 21, 2020

if you use graphql-compose-mongoose

You may get existing Resolver and wrap its resolve method.

UserTC.wrapResolverResolve('createOne', (next) => async (rp) => {
  const doc = await next(rp);
  // any logic after saving document in DB
  return doc;
});

if you create schema in any another way

Just get fieldConfig and wrap its resolve method manually

const fc = schemaComposer.Mutation.getField('create');
const prevResolve = fc.resolve;
fc.resolve = async (source, args, context, info) => {
  const record = await prevResolve(source, args, context, info);
  // any logic after saving
  return record;
};

@nodkz
Copy link
Member

nodkz commented May 21, 2020

@gvvsriram where did you find info about pre-hook? Please send me a link, I try to add these examples there.

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

No branches or pull requests

2 participants