typescript - NestJS/graphql 拦截 graphql 响应
问题描述
在将响应发送回nestjs/graphql之前拦截响应的最佳方法是什么?
我试图拦截查询结果的响应,将一些数据提取到 context.extensions 中,然后再将其发回。我尝试使用 graphql-middleware 应用中间件,但它不起作用。
这就是我尝试做的
export const Pagination: MiddlewareFn = async ({ info }, next) => {
// here i'm trying to extract the data
};
这就是我要放置的地方(resolver.ts)
@UseMiddleware(Pagination)
findAll(options: PaginationInput): Promise<PaginatedReport> {
return applyPagination(this.reportRepository, options);
}
解决方案
为什么不使用专门用于在业务逻辑和后业务逻辑之前拦截响应的拦截器?文档网站上有几个很好的例子(上面链接)。
推荐阅读
- php - PHP多维数组计数和表中的总和
- javascript - 自定义类事件处理
- sorting - Neo4j - 订购作为中间结果一部分的列表
- hibernate - 构建规范(标准 API)
- apache-spark - wholeTextFile() API 极慢不可扩展
- swiftui - Swiftui - 如果显示和隐藏 DatePicker,则缺少 Days 名称
- c# - 如何统一使相机的边缘变灰
- java - 如果在我收到通知的 Firebase 中创建的孩子被删除,我该如何停止通知
- java - Jackson2 将 ObjectNode 保存为字符串
- c# - 即使设置了无限超时,Webrequest 也会超时