1 |
|
2 | import inspect from '../jsutils/inspect';
|
3 | import printPathArray from '../jsutils/printPathArray';
|
4 | import { pathToArray } from '../jsutils/Path';
|
5 | import { GraphQLError } from '../error/GraphQLError';
|
6 | import { coerceInputValue } from './coerceInputValue';
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 | export function coerceValue(inputValue, type, blameNode, path) {
|
14 | var errors = [];
|
15 | var value = coerceInputValue(inputValue, type, function (errorPath, invalidValue, error) {
|
16 | var errorPrefix = 'Invalid value ' + inspect(invalidValue);
|
17 | var pathArray = [].concat(pathToArray(path), errorPath);
|
18 |
|
19 | if (pathArray.length > 0) {
|
20 | errorPrefix += " at \"value".concat(printPathArray(pathArray), "\"");
|
21 | }
|
22 |
|
23 | errors.push(new GraphQLError(errorPrefix + ': ' + error.message, blameNode, undefined, undefined, undefined, error.originalError));
|
24 | });
|
25 | return errors.length > 0 ? {
|
26 | errors: errors,
|
27 | value: undefined
|
28 | } : {
|
29 | errors: undefined,
|
30 | value: value
|
31 | };
|
32 | }
|