UNPKG

@graphql-inspector/ci

Version:

Tooling for GraphQL. Compare GraphQL Schemas, check documents, find breaking changes, find similar types.

73 lines (72 loc) 3.72 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.changesInEnum = changesInEnum; const graphql_1 = require("graphql"); const compare_js_1 = require("../utils/compare.js"); const directive_usage_js_1 = require("./changes/directive-usage.js"); const enum_js_1 = require("./changes/enum.js"); const DEPRECATION_REASON_DEFAULT = 'No longer supported'; function changesInEnum(oldEnum, newEnum, addChange) { (0, compare_js_1.compareLists)(oldEnum?.getValues() ?? [], newEnum.getValues(), { onAdded(value) { addChange((0, enum_js_1.enumValueAdded)(newEnum, value, oldEnum === null)); changesInEnumValue({ newVersion: value, oldVersion: null }, newEnum, addChange); }, onRemoved(value) { addChange((0, enum_js_1.enumValueRemoved)(oldEnum, value)); }, onMutual(value) { changesInEnumValue(value, newEnum, addChange); }, }); (0, compare_js_1.compareDirectiveLists)(oldEnum?.astNode?.directives || [], newEnum.astNode?.directives || [], { onAdded(directive) { addChange((0, directive_usage_js_1.directiveUsageAdded)(graphql_1.Kind.ENUM_TYPE_DEFINITION, directive, newEnum, oldEnum === null)); (0, directive_usage_js_1.directiveUsageChanged)(null, directive, addChange, newEnum); }, onMutual(directive) { (0, directive_usage_js_1.directiveUsageChanged)(directive.oldVersion, directive.newVersion, addChange, newEnum); }, onRemoved(directive) { addChange((0, directive_usage_js_1.directiveUsageRemoved)(graphql_1.Kind.ENUM_TYPE_DEFINITION, directive, newEnum)); }, }); } function changesInEnumValue(value, newEnum, addChange) { const oldValue = value.oldVersion; const newValue = value.newVersion; if ((0, compare_js_1.isNotEqual)(oldValue?.description, newValue.description)) { addChange((0, enum_js_1.enumValueDescriptionChanged)(newEnum, oldValue, newValue)); } if ((0, compare_js_1.isNotEqual)(oldValue?.deprecationReason, newValue.deprecationReason)) { if ((0, compare_js_1.isVoid)(oldValue?.deprecationReason) || oldValue?.deprecationReason === DEPRECATION_REASON_DEFAULT) { addChange((0, enum_js_1.enumValueDeprecationReasonAdded)(newEnum, oldValue, newValue)); } else if ((0, compare_js_1.isVoid)(newValue.deprecationReason) || newValue?.deprecationReason === DEPRECATION_REASON_DEFAULT) { addChange((0, enum_js_1.enumValueDeprecationReasonRemoved)(newEnum, oldValue, newValue)); } else { addChange((0, enum_js_1.enumValueDeprecationReasonChanged)(newEnum, oldValue, newValue)); } } (0, compare_js_1.compareDirectiveLists)(oldValue?.astNode?.directives || [], newValue.astNode?.directives || [], { onAdded(directive) { addChange((0, directive_usage_js_1.directiveUsageAdded)(graphql_1.Kind.ENUM_VALUE_DEFINITION, directive, { type: newEnum, value: newValue, }, oldValue === null)); (0, directive_usage_js_1.directiveUsageChanged)(null, directive, addChange, newEnum, undefined, undefined, newValue); }, onMutual(directive) { (0, directive_usage_js_1.directiveUsageChanged)(directive.oldVersion, directive.newVersion, addChange, newEnum, undefined, undefined, newValue); }, onRemoved(directive) { addChange((0, directive_usage_js_1.directiveUsageRemoved)(graphql_1.Kind.ENUM_VALUE_DEFINITION, directive, { type: newEnum, value: oldValue, })); }, }); }