1 | "use strict";
|
2 |
|
3 | Object.defineProperty(exports, "__esModule", {
|
4 | value: true
|
5 | });
|
6 | exports.coerceValue = coerceValue;
|
7 |
|
8 | var _inspect = _interopRequireDefault(require("../jsutils/inspect"));
|
9 |
|
10 | var _printPathArray = _interopRequireDefault(require("../jsutils/printPathArray"));
|
11 |
|
12 | var _Path = require("../jsutils/Path");
|
13 |
|
14 | var _GraphQLError = require("../error/GraphQLError");
|
15 |
|
16 | var _coerceInputValue = require("./coerceInputValue");
|
17 |
|
18 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 | function 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 | }
|