locatedError.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. 'use strict';
  2. Object.defineProperty(exports, '__esModule', {
  3. value: true,
  4. });
  5. exports.locatedError = locatedError;
  6. var _toError = require('../jsutils/toError.js');
  7. var _GraphQLError = require('./GraphQLError.js');
  8. /**
  9. * Given an arbitrary value, presumably thrown while attempting to execute a
  10. * GraphQL operation, produce a new GraphQLError aware of the location in the
  11. * document responsible for the original Error.
  12. */
  13. function locatedError(rawOriginalError, nodes, path) {
  14. var _nodes;
  15. const originalError = (0, _toError.toError)(rawOriginalError); // Note: this uses a brand-check to support GraphQL errors originating from other contexts.
  16. if (isLocatedGraphQLError(originalError)) {
  17. return originalError;
  18. }
  19. return new _GraphQLError.GraphQLError(originalError.message, {
  20. nodes:
  21. (_nodes = originalError.nodes) !== null && _nodes !== void 0
  22. ? _nodes
  23. : nodes,
  24. source: originalError.source,
  25. positions: originalError.positions,
  26. path,
  27. originalError,
  28. });
  29. }
  30. function isLocatedGraphQLError(error) {
  31. return Array.isArray(error.path);
  32. }