postgraphile-plugin-nested-mutations icon indicating copy to clipboard operation
postgraphile-plugin-nested-mutations copied to clipboard

How to use nested mutations with makeWrapResolversPlugin in filter matching mode

Open Eldow opened this issue 2 years ago • 0 comments

Hello everyone, this issue is more of a call for help.

I am trying to use this core plugin https://www.graphile.org/postgraphile/make-wrap-resolvers-plugin/ in conjunction with postgraphile nested mutations.

// Example: log before and after each mutation runs
module.exports = makeWrapResolversPlugin(
  context => {
    if (context.scope.isRootMutation) {
      return { scope: context.scope };
    }
    return null;
  },
  ({ scope }) => async (resolver, user, args, context, _resolveInfo) => {
    console.log(`Mutation '${scope.fieldName}' starting with arguments:`, args);
    const result = await resolver();
    console.log(`Mutation '${scope.fieldName}' result:`, result);
    return result;
  }
);

In this example, the plugin adds custom logic (console logs) to every root mutation resolvers. I was wondering if there was a way to add custom logic to, let's say, every mutation creating a user, regardless of whether it's a root mutation or a nested one created through this plugin.

Has anyone tried to achieve the same behavior - or has more knowledge than me about what to look for in the resolver context to filter out the right ones ?

Eldow avatar Nov 16 '21 17:11 Eldow