UNPKG

@graphql-inspector/action

Version:

GraphQL Inspector functionality for GitHub Actions

51 lines (50 loc) 2.23 kB
import { compareLists, isNotEqual, isVoid } from '../utils/compare.js'; import { isDeprecated } from '../utils/is-deprecated.js'; import { changesInArgument } from './argument.js'; import { fieldArgumentAdded, fieldArgumentRemoved, fieldDeprecationAdded, fieldDeprecationReasonAdded, fieldDeprecationReasonChanged, fieldDeprecationReasonRemoved, fieldDeprecationRemoved, fieldDescriptionAdded, fieldDescriptionChanged, fieldDescriptionRemoved, fieldTypeChanged, } from './changes/field.js'; export function changesInField(type, oldField, newField, addChange) { if (isNotEqual(oldField.description, newField.description)) { if (isVoid(oldField.description)) { addChange(fieldDescriptionAdded(type, newField)); } else if (isVoid(newField.description)) { addChange(fieldDescriptionRemoved(type, oldField)); } else { addChange(fieldDescriptionChanged(type, oldField, newField)); } } if (isNotEqual(isDeprecated(oldField), isDeprecated(newField))) { if (isDeprecated(newField)) { addChange(fieldDeprecationAdded(type, newField)); } else { addChange(fieldDeprecationRemoved(type, oldField)); } } if (isNotEqual(oldField.deprecationReason, newField.deprecationReason)) { if (isVoid(oldField.deprecationReason)) { addChange(fieldDeprecationReasonAdded(type, newField)); } else if (isVoid(newField.deprecationReason)) { addChange(fieldDeprecationReasonRemoved(type, oldField)); } else { addChange(fieldDeprecationReasonChanged(type, oldField, newField)); } } if (isNotEqual(oldField.type.toString(), newField.type.toString())) { addChange(fieldTypeChanged(type, oldField, newField)); } compareLists(oldField.args, newField.args, { onAdded(arg) { addChange(fieldArgumentAdded(type, newField, arg)); }, onRemoved(arg) { addChange(fieldArgumentRemoved(type, oldField, arg)); }, onMutual(arg) { changesInArgument(type, oldField, arg.oldVersion, arg.newVersion, addChange); }, }); }