src/custom.js
function resolveMiddlewareWrapper(resolve = defaultResolveFn, directives = {}) {
  const serverDirectives = parseSchemaDirectives(directives);

  return (source, args, context, info) => {
    const directives = serverDirectives.concat(
      (info.fieldASTs || info.fieldNodes)[0].directives,
    );
    const directive = directives.filter(
      d => DEFAULT_DIRECTIVES.indexOf(d.name.value) === -1,
    )[0];

    if (!directive) {
      return resolve(source, args, context, info);
    }

    let defer = resolveWithDirective(
      () => Promise.resolve(resolve(source, args, context, info)),
      source,
      directive,
      context,
      info,
    );
    defer.catch(e =>
      resolveWithDirective(
        /* istanbul ignore next */
        () => Promise.reject(e),
        source,
        directive,
        context,
        info,
      ),
    );

    if (directives.length <= 1) {
      return defer;
    }

    for (let directiveNext of directives.slice(1)) {
      defer = defer.then(result =>
        resolveWithDirective(
          () => Promise.resolve(result),
          source,
          directiveNext,
          context,
          info,
        ),
      );
      defer.catch(e =>
        resolveWithDirective(
          () => Promise.reject(e),
          source,
          directiveNext,
          context,
          info,
        ),
      );
    }

    return defer;
  };
}
function resolveMiddlewareWrapper(resolve = defaultResolveFn, directives = {}) {
  const serverDirectives = parseSchemaDirectives(directives);

  return (source, args, context, info) => {
    const directives = serverDirectives.concat(
      (info.fieldASTs || info.fieldNodes)[0].directives,
    );
    const directive = directives.filter(
      d => DEFAULT_DIRECTIVES.indexOf(d.name.value) === -1,
    )[0];

    if (!directive) {
      return resolve(source, args, context, info);
    }

    let defer = resolveWithDirective(
      () => Promise.resolve(resolve(source, args, context, info)),
      source,
      directive,
      context,
      info,
    );
    defer.catch(e =>
      resolveWithDirective(
        /* istanbul ignore next */
        () => Promise.reject(e),
        source,
        directive,
        context,
        info,
      ),
    );

    if (directives.length <= 1) {
      return defer;
    }

    for (let directiveNext of directives.slice(1)) {
      defer = defer.then(result =>
        resolveWithDirective(
          () => Promise.resolve(result),
          source,
          directiveNext,
          context,
          info,
        ),
      );
      defer.catch(e =>
        resolveWithDirective(
          () => Promise.reject(e),
          source,
          directiveNext,
          context,
          info,
        ),
      );
    }

    return defer;
  };
}
function resolveMiddlewareWrapper ( resolve = defaultResolveFn , directives = { } ) { const serverDirectives = parseSchemaDirectives ( directives ) ; return ( source , args , context , info ) => { const directives = serverDirectives . concat ( ( info . fieldASTs || info . fieldNodes ) [ 0 ] . directives , ) ; const directive = directives . filter ( d => DEFAULT_DIRECTIVES . indexOf ( d . name . value ) === - 1 , ) [ 0 ] ; if ( ! directive ) { return resolve ( source , args , context , info ) ; } let defer = resolveWithDirective ( ( ) => Promise . resolve ( resolve ( source , args , context , info ) ) , source , directive , context , info , ) ; defer . catch ( e => resolveWithDirective ( /* istanbul ignore next */ ( ) => Promise . reject ( e ) , source , directive , context , info , ) , ) ; if ( directives . length <= 1 ) { return defer ; } for ( let directiveNext of directives . slice ( 1 ) ) { defer = defer . then ( result => resolveWithDirective ( ( ) => Promise . resolve ( result ) , source , directiveNext , context , info , ) , ) ; defer . catch ( e => resolveWithDirective ( ( ) => Promise . reject ( e ) , source , directiveNext , context , info , ) , ) ; } return defer ; } ; }
If the directive is defined on a field it will execute the custom directive
resolve right after executing the resolve of the field otherwise it will execute
the original resolve of the field
If the directive is defined on a field it will execute the custom directive resolve right after executing the resolve of the field otherwise it will execute the original resolve of the field