isValidLiteralValue.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.isValidLiteralValue = isValidLiteralValue;
  6. var _kinds = require("../language/kinds");
  7. var _visitor = require("../language/visitor");
  8. var _ValuesOfCorrectType = require("../validation/rules/ValuesOfCorrectType");
  9. var _ValidationContext = require("../validation/ValidationContext");
  10. var _schema = require("../type/schema");
  11. var _TypeInfo = require("./TypeInfo");
  12. /**
  13. * Utility which determines if a value literal node is valid for an input type.
  14. *
  15. * Deprecated. Rely on validation for documents containing literal values.
  16. *
  17. * This function will be removed in v15
  18. */
  19. function isValidLiteralValue(type, valueNode) {
  20. var emptySchema = new _schema.GraphQLSchema({});
  21. var emptyDoc = {
  22. kind: _kinds.Kind.DOCUMENT,
  23. definitions: []
  24. };
  25. var typeInfo = new _TypeInfo.TypeInfo(emptySchema, undefined, type);
  26. var context = new _ValidationContext.ValidationContext(emptySchema, emptyDoc, typeInfo);
  27. var visitor = (0, _ValuesOfCorrectType.ValuesOfCorrectType)(context);
  28. (0, _visitor.visit)(valueNode, (0, _visitor.visitWithTypeInfo)(typeInfo, visitor));
  29. return context.getErrors();
  30. }