locatedError.js 851 B

1234567891011121314151617181920212223
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.locatedError = locatedError;
  6. var _GraphQLError = require("./GraphQLError");
  7. /**
  8. * Given an arbitrary Error, presumably thrown while attempting to execute a
  9. * GraphQL operation, produce a new GraphQLError aware of the location in the
  10. * document responsible for the original Error.
  11. */
  12. function locatedError(originalError, nodes, path) {
  13. // Note: this uses a brand-check to support GraphQL errors originating from
  14. // other contexts.
  15. if (originalError && Array.isArray(originalError.path)) {
  16. return originalError;
  17. }
  18. return new _GraphQLError.GraphQLError(originalError && originalError.message, originalError && originalError.nodes || nodes, originalError && originalError.source, originalError && originalError.positions, path, originalError);
  19. }