isValidLiteralValue.mjs 987 B

1234567891011121314151617181920212223242526
  1. import { Kind } from '../language/kinds';
  2. import { visit, visitWithTypeInfo } from '../language/visitor';
  3. import { ValuesOfCorrectType } from '../validation/rules/ValuesOfCorrectType';
  4. import { ValidationContext } from '../validation/ValidationContext';
  5. import { GraphQLSchema } from '../type/schema';
  6. import { 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. export function isValidLiteralValue(type, valueNode) {
  15. var emptySchema = new GraphQLSchema({});
  16. var emptyDoc = {
  17. kind: Kind.DOCUMENT,
  18. definitions: []
  19. };
  20. var typeInfo = new TypeInfo(emptySchema, undefined, type);
  21. var context = new ValidationContext(emptySchema, emptyDoc, typeInfo);
  22. var visitor = ValuesOfCorrectType(context);
  23. visit(valueNode, visitWithTypeInfo(typeInfo, visitor));
  24. return context.getErrors();
  25. }