NoDeprecatedCustomRule.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.NoDeprecatedCustomRule = NoDeprecatedCustomRule;
  6. var _GraphQLError = require("../../../error/GraphQLError");
  7. var _definition = require("../../../type/definition");
  8. /**
  9. * No deprecated
  10. *
  11. * A GraphQL document is only valid if all selected fields and all used enum values have not been
  12. * deprecated.
  13. *
  14. * Note: This rule is optional and is not part of the Validation section of the GraphQL
  15. * Specification. The main purpose of this rule is detection of deprecated usages and not
  16. * necessarily to forbid their use when querying a service.
  17. */
  18. function NoDeprecatedCustomRule(context) {
  19. return {
  20. Field: function Field(node) {
  21. var fieldDef = context.getFieldDef();
  22. var parentType = context.getParentType();
  23. if (parentType && (fieldDef === null || fieldDef === void 0 ? void 0 : fieldDef.deprecationReason) != null) {
  24. context.reportError(new _GraphQLError.GraphQLError("The field ".concat(parentType.name, ".").concat(fieldDef.name, " is deprecated. ") + fieldDef.deprecationReason, node));
  25. }
  26. },
  27. EnumValue: function EnumValue(node) {
  28. var type = (0, _definition.getNamedType)(context.getInputType());
  29. var enumValue = context.getEnumValue();
  30. if (type && (enumValue === null || enumValue === void 0 ? void 0 : enumValue.deprecationReason) != null) {
  31. context.reportError(new _GraphQLError.GraphQLError("The enum value \"".concat(type.name, ".").concat(enumValue.name, "\" is deprecated. ") + enumValue.deprecationReason, node));
  32. }
  33. }
  34. };
  35. }