@graphql-inspector/cli
Version:
Tooling for GraphQL. Compare GraphQL Schemas, check documents, find breaking changes, find similar types.
51 lines (50 loc) • 2.55 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.changesInDirective = changesInDirective;
const compare_js_1 = require("../utils/compare.js");
const directive_js_1 = require("./changes/directive.js");
function changesInDirective(oldDirective, newDirective, addChange) {
if ((0, compare_js_1.isNotEqual)(oldDirective?.description, newDirective.description)) {
addChange((0, directive_js_1.directiveDescriptionChanged)(oldDirective, newDirective));
}
// repeatable removed
if (!newDirective.isRepeatable && oldDirective?.isRepeatable) {
addChange((0, directive_js_1.directiveRepeatableRemoved)(newDirective));
}
// repeatable added
if (newDirective.isRepeatable && !oldDirective?.isRepeatable) {
addChange((0, directive_js_1.directiveRepeatableAdded)(newDirective));
}
const locations = {
added: (0, compare_js_1.diffArrays)(newDirective.locations, oldDirective?.locations ?? []),
removed: (0, compare_js_1.diffArrays)(oldDirective?.locations ?? [], newDirective.locations),
};
// locations added
for (const location of locations.added)
addChange((0, directive_js_1.directiveLocationAdded)(newDirective, location));
// locations removed
for (const location of locations.removed)
addChange((0, directive_js_1.directiveLocationRemoved)(newDirective, location));
(0, compare_js_1.compareLists)(oldDirective?.args ?? [], newDirective.args, {
onAdded(arg) {
addChange((0, directive_js_1.directiveArgumentAdded)(newDirective, arg, oldDirective === null));
},
onRemoved(arg) {
addChange((0, directive_js_1.directiveArgumentRemoved)(newDirective, arg));
},
onMutual(arg) {
changesInDirectiveArgument(newDirective, arg.oldVersion, arg.newVersion, addChange);
},
});
}
function changesInDirectiveArgument(directive, oldArg, newArg, addChange) {
if ((0, compare_js_1.isNotEqual)(oldArg?.description, newArg.description)) {
addChange((0, directive_js_1.directiveArgumentDescriptionChanged)(directive, oldArg, newArg));
}
if ((0, compare_js_1.isNotEqual)(oldArg?.defaultValue, newArg.defaultValue)) {
addChange((0, directive_js_1.directiveArgumentDefaultValueChanged)(directive, oldArg, newArg));
}
if ((0, compare_js_1.isNotEqual)(oldArg.type.toString(), newArg.type.toString())) {
addChange((0, directive_js_1.directiveArgumentTypeChanged)(directive, oldArg, newArg));
}
}