@graphql-inspector/core
Version:
Tooling for GraphQL. Compare GraphQL Schemas, check documents, find breaking changes, find similar types.
168 lines (167 loc) • 7.54 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.enumValueRemovedFromMeta = enumValueRemovedFromMeta;
exports.enumValueRemoved = enumValueRemoved;
exports.enumValueAddedFromMeta = enumValueAddedFromMeta;
exports.enumValueAdded = enumValueAdded;
exports.enumValueDescriptionChangedFromMeta = enumValueDescriptionChangedFromMeta;
exports.enumValueDescriptionChanged = enumValueDescriptionChanged;
exports.enumValueDeprecationReasonChangedFromMeta = enumValueDeprecationReasonChangedFromMeta;
exports.enumValueDeprecationReasonChanged = enumValueDeprecationReasonChanged;
exports.enumValueDeprecationReasonAddedFromMeta = enumValueDeprecationReasonAddedFromMeta;
exports.enumValueDeprecationReasonAdded = enumValueDeprecationReasonAdded;
exports.enumValueDeprecationReasonRemovedFromMeta = enumValueDeprecationReasonRemovedFromMeta;
exports.enumValueDeprecationReasonRemoved = enumValueDeprecationReasonRemoved;
const is_deprecated_js_1 = require("../../utils/is-deprecated.js");
const change_js_1 = require("./change.js");
function buildEnumValueRemovedMessage(args) {
return `Enum value '${args.removedEnumValueName}' ${args.isEnumValueDeprecated ? '(deprecated) ' : ''}was removed from enum '${args.enumName}'`;
}
const enumValueRemovedCriticalityBreakingReason = `Removing an enum value will cause existing queries that use this enum value to error.`;
function enumValueRemovedFromMeta(args) {
return {
type: change_js_1.ChangeType.EnumValueRemoved,
criticality: {
level: change_js_1.CriticalityLevel.Breaking,
reason: enumValueRemovedCriticalityBreakingReason,
},
message: buildEnumValueRemovedMessage(args.meta),
meta: args.meta,
path: [args.meta.enumName, args.meta.removedEnumValueName].join('.'),
};
}
function enumValueRemoved(oldEnum, value) {
return enumValueRemovedFromMeta({
type: change_js_1.ChangeType.EnumValueRemoved,
meta: {
enumName: oldEnum.name,
removedEnumValueName: value.name,
isEnumValueDeprecated: (0, is_deprecated_js_1.isDeprecated)(value),
},
});
}
function buildEnumValueAddedMessage(args) {
return `Enum value '${args.meta.addedEnumValueName}' was added to enum '${args.meta.enumName}'`;
}
const enumValueAddedCriticalityDangerousReason = `Adding an enum value may break existing clients that were not programming defensively against an added case when querying an enum.`;
function enumValueAddedFromMeta(args) {
return {
type: change_js_1.ChangeType.EnumValueAdded,
criticality: {
level: change_js_1.CriticalityLevel.Dangerous,
reason: enumValueAddedCriticalityDangerousReason,
},
message: buildEnumValueAddedMessage(args),
meta: args.meta,
path: [args.meta.enumName, args.meta.addedEnumValueName].join('.'),
};
}
function enumValueAdded(newEnum, value) {
return enumValueAddedFromMeta({
type: change_js_1.ChangeType.EnumValueAdded,
meta: {
enumName: newEnum.name,
addedEnumValueName: value.name,
},
});
}
function buildEnumValueDescriptionChangedMessage(args) {
return args.oldEnumValueDescription === null
? `Description '${args.newEnumValueDescription ?? 'undefined'}' was added to enum value '${args.enumName}.${args.enumValueName}'`
: `Description for enum value '${args.enumName}.${args.enumValueName}' changed from '${args.oldEnumValueDescription ?? 'undefined'}' to '${args.newEnumValueDescription ?? 'undefined'}'`;
}
function enumValueDescriptionChangedFromMeta(args) {
return {
criticality: {
level: change_js_1.CriticalityLevel.NonBreaking,
},
type: change_js_1.ChangeType.EnumValueDescriptionChanged,
message: buildEnumValueDescriptionChangedMessage(args.meta),
path: [args.meta.enumName, args.meta.enumValueName].join('.'),
meta: args.meta,
};
}
function enumValueDescriptionChanged(newEnum, oldValue, newValue) {
return enumValueDescriptionChangedFromMeta({
type: change_js_1.ChangeType.EnumValueDescriptionChanged,
meta: {
enumName: newEnum.name,
enumValueName: oldValue.name,
oldEnumValueDescription: oldValue.description ?? null,
newEnumValueDescription: newValue.description ?? null,
},
});
}
function buildEnumValueDeprecationChangedMessage(args) {
return `Enum value '${args.enumName}.${args.enumValueName}' deprecation reason changed from '${args.oldEnumValueDeprecationReason}' to '${args.newEnumValueDeprecationReason}'`;
}
function enumValueDeprecationReasonChangedFromMeta(args) {
return {
criticality: {
level: change_js_1.CriticalityLevel.NonBreaking,
},
type: change_js_1.ChangeType.EnumValueDeprecationReasonChanged,
message: buildEnumValueDeprecationChangedMessage(args.meta),
path: [args.meta.enumName, args.meta.enumValueName].join('.'),
meta: args.meta,
};
}
function enumValueDeprecationReasonChanged(newEnum, oldValue, newValue) {
return enumValueDeprecationReasonChangedFromMeta({
type: change_js_1.ChangeType.EnumValueDeprecationReasonChanged,
meta: {
enumName: newEnum.name,
enumValueName: oldValue.name,
oldEnumValueDeprecationReason: oldValue.deprecationReason ?? '',
newEnumValueDeprecationReason: newValue.deprecationReason ?? '',
},
});
}
function buildEnumValueDeprecationReasonAddedMessage(args) {
return `Enum value '${args.enumName}.${args.enumValueName}' was deprecated with reason '${args.addedValueDeprecationReason}'`;
}
function enumValueDeprecationReasonAddedFromMeta(args) {
return {
criticality: {
level: change_js_1.CriticalityLevel.NonBreaking,
},
type: change_js_1.ChangeType.EnumValueDeprecationReasonAdded,
message: buildEnumValueDeprecationReasonAddedMessage(args.meta),
path: [args.meta.enumName, args.meta.enumValueName].join('.'),
meta: args.meta,
};
}
function enumValueDeprecationReasonAdded(newEnum, oldValue, newValue) {
return enumValueDeprecationReasonAddedFromMeta({
type: change_js_1.ChangeType.EnumValueDeprecationReasonAdded,
meta: {
enumName: newEnum.name,
enumValueName: oldValue.name,
addedValueDeprecationReason: newValue.deprecationReason ?? '',
},
});
}
function buildEnumValueDeprecationReasonRemovedMessage(args) {
return `Deprecation reason was removed from enum value '${args.enumName}.${args.enumValueName}'`;
}
function enumValueDeprecationReasonRemovedFromMeta(args) {
return {
criticality: {
level: change_js_1.CriticalityLevel.NonBreaking,
},
type: change_js_1.ChangeType.EnumValueDeprecationReasonRemoved,
message: buildEnumValueDeprecationReasonRemovedMessage(args.meta),
path: [args.meta.enumName, args.meta.enumValueName].join('.'),
meta: args.meta,
};
}
function enumValueDeprecationReasonRemoved(newEnum, oldValue, _newValue) {
return enumValueDeprecationReasonRemovedFromMeta({
type: change_js_1.ChangeType.EnumValueDeprecationReasonRemoved,
meta: {
enumName: newEnum.name,
enumValueName: oldValue.name,
removedEnumValueDeprecationReason: oldValue.deprecationReason ?? '',
},
});
}
;