apollo server express,graphql自定义模式指令

apollo server express,graphql自定义模式指令,express,graphql,apollo-server,Express,Graphql,Apollo Server,这对我来说很奇怪。 根据文档,我将我的Auth SchemaDirective设置为: class RequireAuthDirective extends SchemaDirectiveVisitor { visitFieldDefinition(field) { const { resolve = defaultFieldResolver } = field; field.resolve = async (...args) => { let [, par

这对我来说很奇怪。 根据文档,我将我的Auth SchemaDirective设置为:

class RequireAuthDirective extends SchemaDirectiveVisitor {
  visitFieldDefinition(field) {
    const { resolve = defaultFieldResolver } = field;
    field.resolve = async (...args) => {
      let [, params, { req, res, connection }] = args;
      let { user } = req || connection.context;
      if (!!user) {
        return await resolve.apply(this, args);
      } else {
        throw new AuthenticationError('You must be signed in to view this resource.');
      }
    };
  }
}
class RequireAuthDirective extends SchemaDirectiveVisitor {
  visitFieldDefinition(field) {
    const { resolve = defaultFieldResolver } = field;
    field.resolve = async (...args) => {
      let [, params, { req, res, connection }] = args;
      let { user } = req || connection.context;
      if (!!user) {
        if (await isAllowed(user.id, field.name, params)) return await resolve.apply(this, args); // ChkPoint
        throw new AuthenticationError('You are not authorized to access this resource.'); 
      } else {
        throw new AuthenticationError('You must be signed in to access this resource.');
      }
    };
  }
}
这在每个
查询
变异
订阅

但当我使用外部异步方法检查授权时,如下所示:

class RequireAuthDirective extends SchemaDirectiveVisitor {
  visitFieldDefinition(field) {
    const { resolve = defaultFieldResolver } = field;
    field.resolve = async (...args) => {
      let [, params, { req, res, connection }] = args;
      let { user } = req || connection.context;
      if (!!user) {
        return await resolve.apply(this, args);
      } else {
        throw new AuthenticationError('You must be signed in to view this resource.');
      }
    };
  }
}
class RequireAuthDirective extends SchemaDirectiveVisitor {
  visitFieldDefinition(field) {
    const { resolve = defaultFieldResolver } = field;
    field.resolve = async (...args) => {
      let [, params, { req, res, connection }] = args;
      let { user } = req || connection.context;
      if (!!user) {
        if (await isAllowed(user.id, field.name, params)) return await resolve.apply(this, args); // ChkPoint
        throw new AuthenticationError('You are not authorized to access this resource.'); 
      } else {
        throw new AuthenticationError('You must be signed in to access this resource.');
      }
    };
  }
}
这在
查询
突变
中可以正常工作,但在订阅中则不行

注意:如果我删除
ChkPoint
条件(返回true),它将在订阅中工作