[apollo-engine-reporting]: willResolveField 在 stopTiming 后调用

lof*_*nna 5 application-restart apollo-server

我们收到这个错误Error: [internal apollo-server error] willResolveField called after stopTiming!, 这导致节点服务器未经处理的拒绝和频繁重启。

任何有关调试此问题或通常在什么情况下发生的见解。

“阿波罗服务器”:“^2.14.3”,“阿波罗引擎报告”:“2.1.0”

我们如何确定哪个解析器导致了这个问题,因为整个堆栈树来自 graphql 和 apollo 服务器。

谢谢

Der*_*ğlu 0

错误来自ApolloServerPluginUsageReporting

此问题已在 apollo-server-core v3.8.2 版本上修复。Github问题参考

如果您无法升级 Apollo 版本,或者,您可以尝试使用 try/catch 创建函数包装器willResolveField(apollo-server-core) 来抑制它。

  public willResolveField(info: GraphQLResolveInfo): () => void {
    if (!this.startHrTime) {
      throw internalError('willResolveField called before startTiming!');
    }

    try { <<-- put your wrapper here
      if (this.stopped) { 
        throw internalError('willResolveField called after stopTiming!');
      }
    } catch(){}

    const path = info.path;
    const node = this.newNode(path);
    node.type = info.returnType.toString();
    node.parentType = info.parentType.toString();
    node.startTime = durationHrTimeToNanos(process.hrtime(this.startHrTime));
    if (typeof path.key === 'string' && path.key !== info.fieldName) {
      // This field was aliased; send the original field name too (for FieldStats).
      node.originalFieldName = info.fieldName;
    }

    return () => {
      node.endTime = durationHrTimeToNanos(process.hrtime(this.startHrTime));
    };
  }
Run Code Online (Sandbox Code Playgroud)