【发布时间】:2021-12-16 17:14:51
【问题描述】:
有没有办法在解析 graphql 查询之后,但在任何解析器执行之前实现自定义逻辑?
鉴于此查询架构
type Query {
products(...): ProductConnection!
productByHandle(handle: String!): Product
}
如何在解析器有机会执行之前完成为 products 和 productByHandle 查询记录 info 对象的任务?
我基本上是想“连接”到像query:parsed 这样的虚构事件,但它似乎并不存在。我正在使用express-graphql 包。
【问题讨论】:
-
.... 中间件?
-
我不确定你到底在说什么中间件。 Express 中间件不允许您拦截 graphql 解析,它只允许您在 graphql 端点之前/之后做一些事情,这里的要求之一是我可以访问已解析的 graphql 查询,但拦截它的执行。
-
嗯,然后是一些选项github.com/graphql/express-graphql#options ...
customExecuteFn(原始之前)或customParseFn(原始之后)?