UNPKG

@graphql-inspector/cli

Version:

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

79 lines (78 loc) 3.84 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.changesInField = changesInField; const graphql_1 = require("graphql"); const compare_js_1 = require("../utils/compare.js"); const is_deprecated_js_1 = require("../utils/is-deprecated.js"); const argument_js_1 = require("./argument.js"); const directive_usage_js_1 = require("./changes/directive-usage.js"); const field_js_1 = require("./changes/field.js"); const DEPRECATION_REASON_DEFAULT = 'No longer supported'; function changesInField(type, oldField, newField, addChange) { if ((0, compare_js_1.isNotEqual)(oldField?.description, newField.description)) { if ((0, compare_js_1.isVoid)(oldField?.description)) { addChange((0, field_js_1.fieldDescriptionAdded)(type, newField)); } else if ((0, compare_js_1.isVoid)(newField.description)) { addChange((0, field_js_1.fieldDescriptionRemoved)(type, oldField)); } else { addChange((0, field_js_1.fieldDescriptionChanged)(type, oldField, newField)); } } if ((0, compare_js_1.isVoid)(oldField) || !(0, is_deprecated_js_1.isDeprecated)(oldField)) { if ((0, is_deprecated_js_1.isDeprecated)(newField)) { addChange((0, field_js_1.fieldDeprecationAdded)(type, newField)); } } else if (!(0, is_deprecated_js_1.isDeprecated)(newField)) { if ((0, is_deprecated_js_1.isDeprecated)(oldField)) { addChange((0, field_js_1.fieldDeprecationRemoved)(type, oldField)); } } else if ((0, compare_js_1.isNotEqual)(oldField.deprecationReason, newField.deprecationReason)) { if ((0, compare_js_1.isVoid)(oldField.deprecationReason) || oldField.deprecationReason === DEPRECATION_REASON_DEFAULT) { addChange((0, field_js_1.fieldDeprecationReasonAdded)(type, newField)); } else if ((0, compare_js_1.isVoid)(newField.deprecationReason) || newField.deprecationReason === DEPRECATION_REASON_DEFAULT) { addChange((0, field_js_1.fieldDeprecationReasonRemoved)(type, oldField)); } else { addChange((0, field_js_1.fieldDeprecationReasonChanged)(type, oldField, newField)); } } if (!(0, compare_js_1.isVoid)(oldField) && (0, compare_js_1.isNotEqual)(oldField.type.toString(), newField.type.toString())) { addChange((0, field_js_1.fieldTypeChanged)(type, oldField, newField)); } (0, compare_js_1.compareLists)(oldField?.args ?? [], newField.args, { onAdded(arg) { addChange((0, field_js_1.fieldArgumentAdded)(type, newField, arg, oldField === null)); }, onRemoved(arg) { addChange((0, field_js_1.fieldArgumentRemoved)(type, newField, arg)); }, onMutual(arg) { (0, argument_js_1.changesInArgument)(type, newField, arg.oldVersion, arg.newVersion, addChange); }, }); (0, compare_js_1.compareDirectiveLists)(oldField?.astNode?.directives || [], newField.astNode?.directives || [], { onAdded(directive) { addChange((0, directive_usage_js_1.directiveUsageAdded)(graphql_1.Kind.FIELD_DEFINITION, directive, { parentType: type, field: newField, }, oldField === null)); (0, directive_usage_js_1.directiveUsageChanged)(null, directive, addChange, type, newField); }, onMutual(directive) { (0, directive_usage_js_1.directiveUsageChanged)(directive.oldVersion, directive.newVersion, addChange, type, newField); }, onRemoved(arg) { addChange((0, directive_usage_js_1.directiveUsageRemoved)(graphql_1.Kind.FIELD_DEFINITION, arg, { parentType: type, field: oldField, })); }, }); }