Skip to content

Commit

Permalink
AggregateError errors are GraphQL located errors, not the AggregateEr…
Browse files Browse the repository at this point in the history
…ror itself (#6356)

* handle

* show where

* locatedError in AggErr errors list
  • Loading branch information
enisdenjo committed Jul 18, 2024
1 parent 20444fd commit 8094c37
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 14 deletions.
11 changes: 11 additions & 0 deletions .changeset/dirty-panthers-tie.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
'@graphql-tools/delegate': patch
---

AggregateError errors are GraphQL located errors

Instead of transforming the AggregateError itself to a GraphQL located error.

This is because of two reasons:
- AggregateError wont lose the instanceof its class
- Expanding the AggregateError errors will each contain the proper locations
15 changes: 8 additions & 7 deletions packages/delegate/src/checkResultAndHandleErrors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,17 +65,18 @@ export function mergeDataAndErrors(
return { data: relocatedError(errors[0], newPath), unpathedErrors: [] };
}

// We cast path as any for GraphQL.js 14 compat
// locatedError path argument must be defined, but it is just forwarded to a constructor that allows a undefined value
// https://github.com/graphql/graphql-js/blob/b4bff0ba9c15c9d7245dd68556e754c41f263289/src/error/locatedError.js#L25
// https://github.com/graphql/graphql-js/blob/b4bff0ba9c15c9d7245dd68556e754c41f263289/src/error/GraphQLError.js#L19
const combinedError = new AggregateError(
errors,
errors.map(e =>
// We cast path as any for GraphQL.js 14 compat
// locatedError path argument must be defined, but it is just forwarded to a constructor that allows a undefined value
// https://github.com/graphql/graphql-js/blob/b4bff0ba9c15c9d7245dd68556e754c41f263289/src/error/locatedError.js#L25
// https://github.com/graphql/graphql-js/blob/b4bff0ba9c15c9d7245dd68556e754c41f263289/src/error/GraphQLError.js#L19
locatedError(e, undefined as any, path as any),
),
errors.map(error => error.message).join(', \n'),
);
const newError = locatedError(combinedError, undefined as any, path as any);

return { data: newError, unpathedErrors: [] };
return { data: combinedError, unpathedErrors: [] };
}

if (!errors.length) {
Expand Down
15 changes: 8 additions & 7 deletions packages/delegate/src/resolveExternalValue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,15 +157,16 @@ function reportUnpathedErrorsViaNull(unpathedErrors: Array<GraphQLError>) {
return unreportedErrors[0];
}

const combinedError = new AggregateError(
unreportedErrors,
return new AggregateError(
unreportedErrors.map(e =>
// We cast path as any for GraphQL.js 14 compat
// locatedError path argument must be defined, but it is just forwarded to a constructor that allows a undefined value
// https://github.com/graphql/graphql-js/blob/b4bff0ba9c15c9d7245dd68556e754c41f263289/src/error/locatedError.js#L25
// https://github.com/graphql/graphql-js/blob/b4bff0ba9c15c9d7245dd68556e754c41f263289/src/error/GraphQLError.js#L19
locatedError(e, undefined as any, unreportedErrors[0].path as any),
),
unreportedErrors.map(error => error.message).join(', \n'),
);
// We cast path as any for GraphQL.js 14 compat
// locatedError path argument must be defined, but it is just forwarded to a constructor that allows a undefined value
// https://github.com/graphql/graphql-js/blob/b4bff0ba9c15c9d7245dd68556e754c41f263289/src/error/locatedError.js#L25
// https://github.com/graphql/graphql-js/blob/b4bff0ba9c15c9d7245dd68556e754c41f263289/src/error/GraphQLError.js#L19
return locatedError(combinedError, undefined as any, unreportedErrors[0].path as any);
}
}

Expand Down

0 comments on commit 8094c37

Please sign in to comment.