UNPKG

987 BJavaScriptView Raw
1import { Kind } from '../language/kinds';
2import { visit, visitWithTypeInfo } from '../language/visitor';
3import { ValuesOfCorrectType } from '../validation/rules/ValuesOfCorrectType';
4import { ValidationContext } from '../validation/ValidationContext';
5import { GraphQLSchema } from '../type/schema';
6import { TypeInfo } from './TypeInfo';
7/**
8 * Utility which determines if a value literal node is valid for an input type.
9 *
10 * Deprecated. Rely on validation for documents containing literal values.
11 *
12 * This function will be removed in v15
13 */
14
15export function isValidLiteralValue(type, valueNode) {
16 var emptySchema = new GraphQLSchema({});
17 var emptyDoc = {
18 kind: Kind.DOCUMENT,
19 definitions: []
20 };
21 var typeInfo = new TypeInfo(emptySchema, undefined, type);
22 var context = new ValidationContext(emptySchema, emptyDoc, typeInfo);
23 var visitor = ValuesOfCorrectType(context);
24 visit(valueNode, visitWithTypeInfo(typeInfo, visitor));
25 return context.getErrors();
26}