"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var graphql_1 = require("graphql");
var change_1 = require("./change");
var graphql_2 = require("../../utils/graphql");
function fieldRemoved(type, field) {
    return {
        criticality: {
            level: change_1.CriticalityLevel.Breaking,
            reason: field.deprecationReason
                ? "Removing a deprecated field is a breaking change. Before removing it, you may want to look at the field's usage to see the impact of removing the field."
                : "Removing a field is a breaking change. It is preferable to deprecate the field before removing it.",
        },
        type: change_1.ChangeType.FieldRemoved,
        message: "Field '" + field.name + "' was removed from object type '" + type.name + "'",
        path: [type.name, field.name].join('.'),
    };
}
exports.fieldRemoved = fieldRemoved;
function fieldAdded(type, field) {
    return {
        criticality: {
            level: change_1.CriticalityLevel.NonBreaking,
        },
        type: change_1.ChangeType.FieldAdded,
        message: "Field '" + field.name + "' was added to object type '" + type.name + "'",
        path: [type.name, field.name].join('.'),
    };
}
exports.fieldAdded = fieldAdded;
function fieldDescriptionChanged(type, oldField, newField) {
    return {
        criticality: {
            level: change_1.CriticalityLevel.NonBreaking,
        },
        type: change_1.ChangeType.FieldDescriptionChanged,
        message: "Field '" + type.name + "." + oldField.name + "' description changed from '" + oldField.description + "' to '" + newField.description + "'",
        path: [type.name, oldField.name].join('.'),
    };
}
exports.fieldDescriptionChanged = fieldDescriptionChanged;
function fieldDeprecationReasonChanged(type, oldField, newField) {
    return {
        criticality: {
            level: change_1.CriticalityLevel.NonBreaking,
        },
        type: change_1.ChangeType.FieldDeprecationReasonChanged,
        message: "Deprecation reason on field '" + type.name + "." + newField.name + "' has changed from '" + oldField.deprecationReason + "' to '" + newField.deprecationReason + "'",
        path: [type.name, oldField.name].join('.'),
    };
}
exports.fieldDeprecationReasonChanged = fieldDeprecationReasonChanged;
function fieldTypeChanged(type, oldField, newField) {
    return {
        criticality: {
            level: graphql_2.safeChangeForField(oldField.type, newField.type)
                ? change_1.CriticalityLevel.NonBreaking
                : change_1.CriticalityLevel.Breaking,
        },
        type: change_1.ChangeType.FieldTypeChanged,
        message: "Field '" + type + "." + oldField.name + "' changed type from '" + oldField.type + "' to '" + newField.type + "'",
        path: [type.name, oldField.name].join('.'),
    };
}
exports.fieldTypeChanged = fieldTypeChanged;
function fieldArgumentAdded(type, field, arg) {
    return {
        criticality: graphql_1.isNonNullType(arg.type)
            ? {
                level: change_1.CriticalityLevel.Breaking,
                reason: "Adding a required argument to an existing field is a breaking change because it will cause existing uses of this field to error.",
            }
            : {
                level: change_1.CriticalityLevel.NonBreaking,
            },
        type: change_1.ChangeType.FieldArgumentAdded,
        message: "Argument '" + arg.name + ": " + arg.type + "' added to field '" + type.name + "." + field.name + "'",
        path: [type.name, field.name, arg.name].join('.'),
    };
}
exports.fieldArgumentAdded = fieldArgumentAdded;
function fieldArgumentRemoved(type, field, arg) {
    return {
        criticality: {
            level: change_1.CriticalityLevel.Breaking,
            reason: "Removing a field argument is a breaking change because it will cause existing queries that use this argument to error.",
        },
        type: change_1.ChangeType.FieldArgumentRemoved,
        message: "Argument '" + arg.name + ": " + arg.type + "' was removed from field '" + type.name + "." + field.name + "'",
        path: [type.name, field.name, arg.name].join('.'),
    };
}
exports.fieldArgumentRemoved = fieldArgumentRemoved;
//# sourceMappingURL=field.js.map