All Downloads are FREE. Search and download functionalities are using the official Maven repository.

node_modules.graphql.utilities.isValidLiteralValue.js.flow Maven / Gradle / Ivy

There is a newer version: 3.3.1
Show newest version
/**
 * 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.
 *
 * @flow strict
 */

import { TypeInfo } from './TypeInfo';
import type { GraphQLError } from '../error/GraphQLError';
import type { ValueNode } from '../language/ast';
import { Kind } from '../language/kinds';
import { visit, visitWithTypeInfo } from '../language/visitor';
import type { GraphQLInputType } from '../type/definition';
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.
 */
export function isValidLiteralValue(
  type: GraphQLInputType,
  valueNode: ValueNode,
): $ReadOnlyArray {
  const emptySchema = new GraphQLSchema({});
  const emptyDoc = { kind: Kind.DOCUMENT, definitions: [] };
  const typeInfo = new TypeInfo(emptySchema, undefined, type);
  const context = new ValidationContext(emptySchema, emptyDoc, typeInfo);
  const visitor = ValuesOfCorrectType(context);
  visit(valueNode, visitWithTypeInfo(typeInfo, visitor));
  return context.getErrors();
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy