Skip to content

Commit

Permalink
engine-reporting: Capture operationName and document within errors.
Browse files Browse the repository at this point in the history
This is another take on #2659 which has been otherwise excluded from the
2.6.0 release.

The work in #2659 was meant to ensure that the `document` and
`operationName` were set at the appropriate locations within the lifecycle
events for the `graphql-extensions` module, specifically when an error had
been thrown within `didResolveOperation` of the new request pipeline.

While the solution in #2659 certainly works, it introduced a new life-cycle
method for details which we could also calculate without adding to the
API surface area by using information which was already exposed.

Even though `graphql-extensions` is no longer really being supported,
avoiding growth on the API surface area of `graphql-extensions` is still
important for any API!

Ref: #2659
  • Loading branch information
abernix committed May 22, 2019
1 parent 81282f9 commit 6cf861c
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions packages/apollo-engine-reporting/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,12 +199,18 @@ export class EngineReportingExtension<TContext = any>
this.trace.fullQueryCacheHit = !!o.requestContext.metrics
.responseCacheHit;

const operationName = this.operationName || '';
// If the `operationName` was not already set elsewhere, for example,
// through the `executionDidStart` or the `willResolveField` hooks, then
// we'll resort to using the `operationName` which was requested to be
// executed by the client.
const operationName =
this.operationName || o.requestContext.operationName || '';
const documentAST = this.documentAST || o.requestContext.document;

this.addTrace({
operationName,
queryHash,
documentAST: this.documentAST,
documentAST,
queryString: this.queryString || '',
trace: this.trace,
});
Expand Down

0 comments on commit 6cf861c

Please sign in to comment.