UNPKG

1.3 kBJavaScriptView Raw
1'use strict';
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.isValidLiteralValue = isValidLiteralValue;
7
8var _TypeInfo = require('./TypeInfo');
9
10var _kinds = require('../language/kinds');
11
12var _visitor = require('../language/visitor');
13
14var _schema = require('../type/schema');
15
16var _ValuesOfCorrectType = require('../validation/rules/ValuesOfCorrectType');
17
18var _validate = require('../validation/validate');
19
20/**
21 * Utility which determines if a value literal node is valid for an input type.
22 *
23 * Deprecated. Rely on validation for documents containing literal values.
24 */
25/**
26 * Copyright (c) 2015-present, Facebook, Inc.
27 *
28 * This source code is licensed under the MIT license found in the
29 * LICENSE file in the root directory of this source tree.
30 *
31 *
32 */
33
34function isValidLiteralValue(type, valueNode) {
35 var emptySchema = new _schema.GraphQLSchema({});
36 var emptyDoc = { kind: _kinds.DOCUMENT, definitions: [] };
37 var typeInfo = new _TypeInfo.TypeInfo(emptySchema, undefined, type);
38 var context = new _validate.ValidationContext(emptySchema, emptyDoc, typeInfo);
39 var visitor = (0, _ValuesOfCorrectType.ValuesOfCorrectType)(context);
40 (0, _visitor.visit)(valueNode, (0, _visitor.visitWithTypeInfo)(typeInfo, visitor));
41 return context.getErrors();
42}
\No newline at end of file