lofty khanna
lofty khanna

Reputation: 111

[apollo-engine-reporting]: willResolveField called after stopTiming

We are receiving this error Error: [internal apollo-server error] willResolveField called after stopTiming!, this is leading to unhandled rejection and frequent restart of node server.

Any insight to debug this or in what situation it usually happens.

"apollo-server": "^2.14.3", "apollo-engine-reporting": "2.1.0"

How do we pinpoint which resolver is causing this issue as entire stack tree is from graphql and apollo server.

Thanks

Upvotes: 10

Views: 436

Answers (1)

Derviş Kayımbaşıoğlu
Derviş Kayımbaşıoğlu

Reputation: 30645

The error is coming from ApolloServerPluginUsageReporting

This issue is fixed on apollo-server-core version v3.8.2. Github issue Reference

If you cannot upgrade your Apollo version, alternatively, you can try to create wrapper around function willResolveField (apollo-server-core) with try/catch to suppress it.

  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));
    };
  }

Upvotes: 0

Related Questions