src/index.js
function wrapFieldsWithMiddleware(type, deepWrap = true, typeMet = {}) {
  if (!type) {
    return;
  }

  let fields = type._fields;
  typeMet[type.name] = true;
  for (let label in fields) {
    let field = fields[label];
    if (field && !typeMet[field.type.name]) {
      if (!!field && typeof field == 'object') {
        field.resolve = resolveMiddlewareWrapper(
          field.resolve,
          field.directives,
        );
        if (field.type._fields && deepWrap) {
          wrapFieldsWithMiddleware(field.type, deepWrap, typeMet);
        } else if (field.type.ofType && field.type.ofType._fields && deepWrap) {
          let child = field.type;
          while (child.ofType) {
            child = child.ofType;
          }
          if (child._fields) {
            wrapFieldsWithMiddleware(child._fields);
          }
        }
      }
    }
  }
}
function wrapFieldsWithMiddleware(type, deepWrap = true, typeMet = {}) {
  if (!type) {
    return;
  }

  let fields = type._fields;
  typeMet[type.name] = true;
  for (let label in fields) {
    let field = fields[label];
    if (field && !typeMet[field.type.name]) {
      if (!!field && typeof field == 'object') {
        field.resolve = resolveMiddlewareWrapper(
          field.resolve,
          field.directives,
        );
        if (field.type._fields && deepWrap) {
          wrapFieldsWithMiddleware(field.type, deepWrap, typeMet);
        } else if (field.type.ofType && field.type.ofType._fields && deepWrap) {
          let child = field.type;
          while (child.ofType) {
            child = child.ofType;
          }
          if (child._fields) {
            wrapFieldsWithMiddleware(child._fields);
          }
        }
      }
    }
  }
}
function wrapFieldsWithMiddleware ( type , deepWrap = true , typeMet = { } ) { if ( ! type ) { return ; } let fields = type . _fields ; typeMet [ type . name ] = true ; for ( let label in fields ) { let field = fields [ label ] ; if ( field && ! typeMet [ field . type . name ] ) { if ( ! ! field && typeof field == 'object' ) { field . resolve = resolveMiddlewareWrapper ( field . resolve , field . directives , ) ; if ( field . type . _fields && deepWrap ) { wrapFieldsWithMiddleware ( field . type , deepWrap , typeMet ) ; } else if ( field . type . ofType && field . type . ofType . _fields && deepWrap ) { let child = field . type ; while ( child . ofType ) { child = child . ofType ; } if ( child . _fields ) { wrapFieldsWithMiddleware ( child . _fields ) ; } } } } } }
Scanning the shema and wrapping the resolve of each field with the support
of the graphql custom directives resolve execution
Scanning the shema and wrapping the resolve of each field with the support of the graphql custom directives resolve execution