Files
Superalgos/server/node_modules/graphql/utilities/isValidLiteralValue.mjs
T
2018-09-03 15:19:57 +02:00

34 lines
1.2 KiB
JavaScript

/**
* Copyright (c) 2015-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* strict
*/
import { TypeInfo } from './TypeInfo';
import { Kind } from '../language/kinds';
import { visit, visitWithTypeInfo } from '../language/visitor';
import { GraphQLSchema } from '../type/schema';
import { ValuesOfCorrectType } from '../validation/rules/ValuesOfCorrectType';
import { ValidationContext } from '../validation/ValidationContext';
/**
* Utility which determines if a value literal node is valid for an input type.
*
* Deprecated. Rely on validation for documents containing literal values.
*
* This function will be removed in v15
*/
export function isValidLiteralValue(type, valueNode) {
var emptySchema = new GraphQLSchema({});
var emptyDoc = {
kind: Kind.DOCUMENT,
definitions: []
};
var typeInfo = new TypeInfo(emptySchema, undefined, type);
var context = new ValidationContext(emptySchema, emptyDoc, typeInfo);
var visitor = ValuesOfCorrectType(context);
visit(valueNode, visitWithTypeInfo(typeInfo, visitor));
return context.getErrors();
}