You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

applyResolversEnhanceMap无法为resolvers添加自定义装饰器问题求助

问题解决方法

核心错误点

你将applyResolversEnhanceMap的调用放在了buildSchema之后,增强映射的逻辑必须在schema生成之前执行,才能将自定义装饰器注入到typegraphql-prisma生成的resolver类中,等schema构建完成后再调用增强方法不会对已经生成的schema产生任何效果。

修正后的index.ts代码

const app = express();
const http = createServer(app);

// 先应用增强映射
applyResolversEnhanceMap(mapped);
// 再构建schema
const schema = await buildSchema({
  resolvers: [...resolvers, AuthResolver, ImageResolver, CardResolver],
  validate: false,
});

// 后续其他代码

其余排查点

如果调整顺序后依然不生效,可以逐一检查以下配置:

  • 确认你传入buildSchema的resolvers数组确实包含typegraphql-prisma自动生成的Like模型相关resolver,不要漏导生成的resolver文件
  • 确认ResolversEnhanceMap是从@generated/type-graphql包导入的自动生成类型,不是自己手动定义的同名类型
  • 确认RateLimitMiddleware中使用的createMethodDecorator是从type-graphql包导入的方法,不要导错其他包的同名API

内容的提问来源于stack exchange,提问作者Californium

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.26 00:54:04