UNPKG

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