How to implement an after doc saved callback or chain a promise after a resolver?
Hi, I need to implement an after-doc-saved callback or to chain a promise after a mutation resolver in order to add later subscriptions. How can I implement that? Using .wrapResolve() maybe but how should I do it properly? Thanks.
As refer you may read the following issues
- https://github.com/graphql-compose/graphql-compose/issues/112#issuecomment-367616354
- https://github.com/graphql-compose/graphql-compose/issues/72#issuecomment-317243160
const middleware = next => async rp => {
// before mutation logic
// somehow change `rp`
const payload = await next(rp);
// after mutation logic change `payload`
// eg. payload.record will contain mongoose document
return payload;
}
schemaComposer.Mutation.addFields({
userCreate: UserTC
.getResolver('createOne')
.wrapResolve(middleware),
});
Also you may read this https://graphql-compose.github.io/docs/en/basics-resolvers.html#via-resolverwrapresolve
If you will have questions or additions – feel free to continue the discussion with code examples.
As refer you may read the following issues
const middleware = next => async rp => { // before mutation logic // somehow change `rp` const payload = await next(rp); // after mutation logic change `payload` // eg. payload.record will contain mongoose document return payload; } schemaComposer.Mutation.addFields({ userCreate: UserTC .getResolver('createOne') .wrapResolve(middleware), });
This makes a lot of sense. Thought on awaiting but didn't know if it was the proper way. Thanks @nodkz ! I'll try it this way.