Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

engine-reporting: Handle errors within didResolveOperation life-cycle hook. #2710

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 23 additions & 7 deletions packages/apollo-server-core/src/requestPipeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ export {
};

import createSHA from './utils/createSHA';
import { HttpQueryError } from './runHttpQuery';

export const APQ_CACHE_PREFIX = 'apq:';

Expand Down Expand Up @@ -290,13 +291,26 @@ export async function processGraphQLRequest<TContext>(
requestContext.operationName =
(operation && operation.name && operation.name.value) || null;

await dispatcher.invokeHookAsync(
'didResolveOperation',
requestContext as WithRequired<
typeof requestContext,
'document' | 'source' | 'operation' | 'operationName' | 'metrics'
>,
);
try {
await dispatcher.invokeHookAsync(
'didResolveOperation',
requestContext as WithRequired<
typeof requestContext,
'document' | 'source' | 'operation' | 'operationName' | 'metrics'
>,
);
} catch (err) {
// XXX: The HttpQueryError is special-cased here because we currently
// depend on `throw`-ing an error from the `didResolveOperation` hook
// we've implemented in `runHttpQuery.ts`'s `checkOperationPlugin`:
// https://git.io/fj427. This could be perceived as a feature, but
// for the time-being this just maintains existing behavior for what
// happens when `throw`-ing an `HttpQueryError` in `didResolveOperation`.
if (err instanceof HttpQueryError) {
throw err;
}
return sendErrorResponse(err);
}

// Now that we've gone through the pre-execution phases of the request
// pipeline, and given plugins appropriate ability to object (by throwing
Expand Down Expand Up @@ -481,6 +495,8 @@ export async function processGraphQLRequest<TContext>(
? errorOrErrors
: [errorOrErrors];

extensionStack.didEncounterErrors(errors);

return sendResponse({
errors: formatErrors(
errors.map(err =>
Expand Down