Apollo GraphQL 在调用 willResolveField 之前解析字段。字段 'resolve' 实际发生的方式和地点是什么?

Apollo GraphQL resolves the field before calling `willResolveField`. How and where is the field 'resolve' actually happening?

我正在尝试构建自定义 Apollo 扩展以捕获解析器的一些性能指标(执行持续时间)并将它们记录到 APM 工具中。从 Apollo 发布的 Apollo documentation, Github issue here and an example 中,我发现方法 willResolveField 在被重写时接收 GraphQLResolveInfo (这又具有父类型 parentType 和字段名称 fieldName).如果可以注意到,当 Apollo 服务器调用此方法时,字段已经解析。在将其发送到 willResolveField 之前,有人知道该字段解析实际发生​​的位置吗?

另一方面,除非我的理解有误 - willResolveField 这个名字似乎具有误导性。有人可以解释一下吗?

我要实现的示例代码

class GraphQLAPMExtension implements GraphQLExtension<TContext> {
 requestDidStart(options:{ request, operationName, ... }) {
  // perform APM specifics to log the request and other info
  return (...errors) => {
    if(errors.length) {
     // some more custom APM stuff!
    }
  }
 }

 willResolveField(source, args, context: TContext, info: GraphQLResolveInfo) {
  // info contains parentType and fieldName
  // and it seems to be that fields are already resolved and passed to this function
 }

}

在深入研究 graphql 包之后。它看起来像函数 resolveFieldValueOrError 做的决议。它可以在 ./execution 部分下找到。看来我将不得不分叉 graphQl 项目并进行我希望的修改。

另一个更实际的方向是跟踪 Apollo 服务器创建的跟踪参数。经过一些快速挖掘,发现它正在使用 apollo-engine-reporting 包。

ApolloServer 中已经内置了用于跟踪请求的扩展。可以找到源代码here。听起来你可以 fork 那个。