coerceValue.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.coerceValue = coerceValue;
  6. var _inspect = _interopRequireDefault(require("../jsutils/inspect"));
  7. var _printPathArray = _interopRequireDefault(require("../jsutils/printPathArray"));
  8. var _Path = require("../jsutils/Path");
  9. var _GraphQLError = require("../error/GraphQLError");
  10. var _coerceInputValue = require("./coerceInputValue");
  11. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  12. /* istanbul ignore file */
  13. /**
  14. * Deprecated. Use coerceInputValue() directly for richer information.
  15. *
  16. * This function will be removed in v15
  17. */
  18. function coerceValue(inputValue, type, blameNode, path) {
  19. var errors = [];
  20. var value = (0, _coerceInputValue.coerceInputValue)(inputValue, type, function (errorPath, invalidValue, error) {
  21. var errorPrefix = 'Invalid value ' + (0, _inspect.default)(invalidValue);
  22. var pathArray = [].concat((0, _Path.pathToArray)(path), errorPath);
  23. if (pathArray.length > 0) {
  24. errorPrefix += " at \"value".concat((0, _printPathArray.default)(pathArray), "\"");
  25. }
  26. errors.push(new _GraphQLError.GraphQLError(errorPrefix + ': ' + error.message, blameNode, undefined, undefined, undefined, error.originalError));
  27. });
  28. return errors.length > 0 ? {
  29. errors: errors,
  30. value: undefined
  31. } : {
  32. errors: undefined,
  33. value: value
  34. };
  35. }