apollo-server-errors
Advanced tools
Comparing version
@@ -151,16 +151,3 @@ "use strict"; | ||
const { formatter, debug } = options; | ||
const flattenedErrors = []; | ||
errors.forEach(error => { | ||
if (Array.isArray(error.errors)) { | ||
error.errors.forEach(e => flattenedErrors.push(e)); | ||
} | ||
else if (error.originalError && | ||
Array.isArray(error.originalError.errors)) { | ||
error.originalError.errors.forEach(e => flattenedErrors.push(e)); | ||
} | ||
else { | ||
flattenedErrors.push(error); | ||
} | ||
}); | ||
const enrichedErrors = flattenedErrors.map(error => enrichError(error, debug)); | ||
const enrichedErrors = errors.map(error => enrichError(error, debug)); | ||
if (!formatter) { | ||
@@ -167,0 +154,0 @@ return enrichedErrors; |
{ | ||
"name": "apollo-server-errors", | ||
"version": "2.0.0-rc.6", | ||
"version": "2.0.0-rc.7", | ||
"author": "opensource@apollographql.com", | ||
@@ -42,3 +42,3 @@ "license": "MIT", | ||
], | ||
"testRegex": "/__tests__/.*$", | ||
"testRegex": "src/__tests__/.*$", | ||
"globals": { | ||
@@ -45,0 +45,0 @@ "ts-jest": { |
@@ -225,26 +225,23 @@ import { GraphQLError } from 'graphql'; | ||
const flattenedErrors: Error[] = []; | ||
errors.forEach(error => { | ||
// Errors that occur in graphql-tools can contain an errors array that contains the errors thrown in a merged schema | ||
// https://github.com/apollographql/graphql-tools/blob/3d53986ca/src/stitching/errors.ts#L104-L107 | ||
// | ||
// They are are wrapped in an extra GraphQL error | ||
// https://github.com/apollographql/graphql-tools/blob/3d53986ca/src/stitching/errors.ts#L109-L113 | ||
// which calls: | ||
// https://github.com/graphql/graphql-js/blob/0a30b62964/src/error/locatedError.js#L18-L37 | ||
if (Array.isArray((error as any).errors)) { | ||
(error as any).errors.forEach(e => flattenedErrors.push(e)); | ||
} else if ( | ||
(error as any).originalError && | ||
Array.isArray((error as any).originalError.errors) | ||
) { | ||
(error as any).originalError.errors.forEach(e => flattenedErrors.push(e)); | ||
} else { | ||
flattenedErrors.push(error); | ||
} | ||
}); | ||
// Errors that occur in graphql-tools can contain an errors array that contains the errors thrown in a merged schema | ||
// https://github.com/apollographql/graphql-tools/blob/3d53986ca/src/stitching/errors.ts#L104-L107 | ||
// | ||
// They are are wrapped in an extra GraphQL error | ||
// https://github.com/apollographql/graphql-tools/blob/3d53986ca/src/stitching/errors.ts#L109-L113 | ||
// which calls: | ||
// https://github.com/graphql/graphql-js/blob/0a30b62964/src/error/locatedError.js#L18-L37 | ||
// Some processing for these nested errors could be done here: | ||
// | ||
// if (Array.isArray((error as any).errors)) { | ||
// (error as any).errors.forEach(e => flattenedErrors.push(e)); | ||
// } else if ( | ||
// (error as any).originalError && | ||
// Array.isArray((error as any).originalError.errors) | ||
// ) { | ||
// (error as any).originalError.errors.forEach(e => flattenedErrors.push(e)); | ||
// } else { | ||
// flattenedErrors.push(error); | ||
// } | ||
const enrichedErrors = flattenedErrors.map(error => | ||
enrichError(error, debug), | ||
); | ||
const enrichedErrors = errors.map(error => enrichError(error, debug)); | ||
@@ -251,0 +248,0 @@ if (!formatter) { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
22680
-4.09%446
-3.46%