locatedError.mjs 709 B

123456789101112131415161718
  1. import { GraphQLError } from "./GraphQLError.mjs";
  2. /**
  3. * Given an arbitrary Error, presumably thrown while attempting to execute a
  4. * GraphQL operation, produce a new GraphQLError aware of the location in the
  5. * document responsible for the original Error.
  6. */
  7. export function locatedError(originalError, nodes, path) {
  8. var _nodes;
  9. // Note: this uses a brand-check to support GraphQL errors originating from
  10. // other contexts.
  11. if (Array.isArray(originalError.path)) {
  12. return originalError;
  13. }
  14. return new GraphQLError(originalError.message, (_nodes = originalError.nodes) !== null && _nodes !== void 0 ? _nodes : nodes, originalError.source, originalError.positions, path, originalError);
  15. }