@graphql-inspector/core
Version:
Tooling for GraphQL. Compare GraphQL Schemas, check documents, find breaking changes, find similar types.
290 lines (289 loc) • 13.2 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.directiveRemovedFromMeta = directiveRemovedFromMeta;
exports.directiveRemoved = directiveRemoved;
exports.directiveAddedFromMeta = directiveAddedFromMeta;
exports.directiveAdded = directiveAdded;
exports.directiveDescriptionChangedFromMeta = directiveDescriptionChangedFromMeta;
exports.directiveDescriptionChanged = directiveDescriptionChanged;
exports.directiveLocationAddedFromMeta = directiveLocationAddedFromMeta;
exports.directiveLocationAdded = directiveLocationAdded;
exports.directiveLocationRemovedFromMeta = directiveLocationRemovedFromMeta;
exports.directiveLocationRemoved = directiveLocationRemoved;
exports.directiveArgumentAddedFromMeta = directiveArgumentAddedFromMeta;
exports.directiveArgumentAdded = directiveArgumentAdded;
exports.directiveArgumentRemovedFromMeta = directiveArgumentRemovedFromMeta;
exports.directiveArgumentRemoved = directiveArgumentRemoved;
exports.directiveArgumentDescriptionChangedFromMeta = directiveArgumentDescriptionChangedFromMeta;
exports.directiveArgumentDescriptionChanged = directiveArgumentDescriptionChanged;
exports.directiveArgumentDefaultValueChangedFromMeta = directiveArgumentDefaultValueChangedFromMeta;
exports.directiveArgumentDefaultValueChanged = directiveArgumentDefaultValueChanged;
exports.directiveArgumentTypeChangedFromMeta = directiveArgumentTypeChangedFromMeta;
exports.directiveArgumentTypeChanged = directiveArgumentTypeChanged;
const graphql_1 = require("graphql");
const graphql_js_1 = require("../../utils/graphql.js");
const string_js_1 = require("../../utils/string.js");
const change_js_1 = require("./change.js");
function buildDirectiveRemovedMessage(args) {
return `Directive '${args.removedDirectiveName}' was removed`;
}
const directiveRemovedCriticalityBreakingReason = `A directive could be in use of a client application. Removing it could break the client application.`;
function directiveRemovedFromMeta(args) {
return {
criticality: {
level: change_js_1.CriticalityLevel.Breaking,
reason: directiveRemovedCriticalityBreakingReason,
},
type: change_js_1.ChangeType.DirectiveRemoved,
message: buildDirectiveRemovedMessage(args.meta),
path: `@${args.meta.removedDirectiveName}`,
meta: args.meta,
};
}
function directiveRemoved(directive) {
return directiveRemovedFromMeta({
type: change_js_1.ChangeType.DirectiveRemoved,
meta: {
removedDirectiveName: directive.name,
},
});
}
function buildDirectiveAddedMessage(args) {
return `Directive '${args.addedDirectiveName}' was added`;
}
function directiveAddedFromMeta(args) {
return {
criticality: {
level: change_js_1.CriticalityLevel.NonBreaking,
},
type: change_js_1.ChangeType.DirectiveAdded,
message: buildDirectiveAddedMessage(args.meta),
path: `@${args.meta.addedDirectiveName}`,
meta: args.meta,
};
}
function directiveAdded(directive) {
return directiveAddedFromMeta({
type: change_js_1.ChangeType.DirectiveAdded,
meta: {
addedDirectiveName: directive.name,
},
});
}
function buildDirectiveDescriptionChangedMessage(args) {
return `Directive '${args.directiveName}' description changed from '${args.oldDirectiveDescription ?? 'undefined'}' to '${args.newDirectiveDescription ?? 'undefined'}'`;
}
function directiveDescriptionChangedFromMeta(args) {
return {
criticality: {
level: change_js_1.CriticalityLevel.NonBreaking,
},
type: change_js_1.ChangeType.DirectiveDescriptionChanged,
message: buildDirectiveDescriptionChangedMessage(args.meta),
path: `@${args.meta.directiveName}`,
meta: args.meta,
};
}
function directiveDescriptionChanged(oldDirective, newDirective) {
return directiveDescriptionChangedFromMeta({
type: change_js_1.ChangeType.DirectiveDescriptionChanged,
meta: {
directiveName: oldDirective.name,
oldDirectiveDescription: oldDirective.description ?? null,
newDirectiveDescription: newDirective.description ?? null,
},
});
}
function buildDirectiveLocationAddedMessage(args) {
return `Location '${args.addedDirectiveLocation}' was added to directive '${args.directiveName}'`;
}
function directiveLocationAddedFromMeta(args) {
return {
criticality: {
level: change_js_1.CriticalityLevel.NonBreaking,
},
type: change_js_1.ChangeType.DirectiveLocationAdded,
message: buildDirectiveLocationAddedMessage(args.meta),
path: `@${args.meta.directiveName}`,
meta: args.meta,
};
}
function directiveLocationAdded(directive, location) {
return directiveLocationAddedFromMeta({
type: change_js_1.ChangeType.DirectiveLocationAdded,
meta: {
directiveName: directive.name,
addedDirectiveLocation: location.toString(),
},
});
}
function buildDirectiveLocationRemovedMessage(args) {
return `Location '${args.removedDirectiveLocation}' was removed from directive '${args.directiveName}'`;
}
const directiveLocationRemovedBreakingReason = `A directive could be in use of a client application. Removing it could break the client application.`;
function directiveLocationRemovedFromMeta(args) {
return {
criticality: {
level: change_js_1.CriticalityLevel.Breaking,
reason: directiveLocationRemovedBreakingReason,
},
type: change_js_1.ChangeType.DirectiveLocationRemoved,
message: buildDirectiveLocationRemovedMessage(args.meta),
path: `@${args.meta.directiveName}`,
meta: args.meta,
};
}
function directiveLocationRemoved(directive, location) {
return directiveLocationRemovedFromMeta({
type: change_js_1.ChangeType.DirectiveLocationRemoved,
meta: {
directiveName: directive.name,
removedDirectiveLocation: location.toString(),
},
});
}
const directiveArgumentAddedBreakingReason = `A directive could be in use of a client application. Adding a non-nullable argument will break those clients.`;
const directiveArgumentNonBreakingReason = `A directive could be in use of a client application. Adding a non-nullable argument will break those clients.`;
function directiveArgumentAddedFromMeta(args) {
return {
criticality: args.meta.addedDirectiveArgumentTypeIsNonNull
? {
level: change_js_1.CriticalityLevel.Breaking,
reason: directiveArgumentAddedBreakingReason,
}
: {
level: change_js_1.CriticalityLevel.NonBreaking,
reason: directiveArgumentNonBreakingReason,
},
type: change_js_1.ChangeType.DirectiveArgumentAdded,
message: `Argument '${args.meta.addedDirectiveArgumentName}' was added to directive '${args.meta.directiveName}'`,
path: `@${args.meta.directiveName}`,
meta: args.meta,
};
}
function directiveArgumentAdded(directive, arg) {
return directiveArgumentAddedFromMeta({
type: change_js_1.ChangeType.DirectiveArgumentAdded,
meta: {
directiveName: directive.name,
addedDirectiveArgumentName: arg.name,
addedDirectiveArgumentTypeIsNonNull: (0, graphql_1.isNonNullType)(arg.type),
},
});
}
function buildDirectiveArgumentRemovedMessage(args) {
return `Argument '${args.removedDirectiveArgumentName}' was removed from directive '${args.directiveName}'`;
}
const directiveArgumentRemovedBreakingReason = `A directive argument could be in use of a client application. Removing the argument can break client applications.`;
function directiveArgumentRemovedFromMeta(args) {
return {
criticality: {
level: change_js_1.CriticalityLevel.Breaking,
reason: directiveArgumentRemovedBreakingReason,
},
type: change_js_1.ChangeType.DirectiveArgumentRemoved,
message: buildDirectiveArgumentRemovedMessage(args.meta),
path: `@${args.meta.directiveName}.${args.meta.removedDirectiveArgumentName}`,
meta: args.meta,
};
}
function directiveArgumentRemoved(directive, arg) {
return directiveArgumentRemovedFromMeta({
type: change_js_1.ChangeType.DirectiveArgumentRemoved,
meta: {
directiveName: directive.name,
removedDirectiveArgumentName: arg.name,
},
});
}
function buildDirectiveArgumentDescriptionChangedMessage(args) {
return `Description for argument '${args.directiveArgumentName}' on directive '${args.directiveName}' changed from '${args.oldDirectiveArgumentDescription}' to '${args.newDirectiveArgumentDescription}'`;
}
function directiveArgumentDescriptionChangedFromMeta(args) {
return {
criticality: {
level: change_js_1.CriticalityLevel.NonBreaking,
},
type: change_js_1.ChangeType.DirectiveArgumentDescriptionChanged,
message: buildDirectiveArgumentDescriptionChangedMessage(args.meta),
path: `@${args.meta.directiveName}.${args.meta.directiveArgumentName}`,
meta: args.meta,
};
}
function directiveArgumentDescriptionChanged(directive, oldArg, newArg) {
return directiveArgumentDescriptionChangedFromMeta({
type: change_js_1.ChangeType.DirectiveArgumentDescriptionChanged,
meta: {
directiveName: directive.name,
directiveArgumentName: oldArg.name,
oldDirectiveArgumentDescription: oldArg.description ?? null,
newDirectiveArgumentDescription: newArg.description ?? null,
},
});
}
function buildDirectiveArgumentDefaultValueChanged(args) {
return args.oldDirectiveArgumentDefaultValue === undefined
? `Default value '${args.newDirectiveArgumentDefaultValue}' was added to argument '${args.directiveArgumentName}' on directive '${args.directiveName}'`
: `Default value for argument '${args.directiveArgumentName}' on directive '${args.directiveName}' changed from '${args.oldDirectiveArgumentDefaultValue}' to '${args.newDirectiveArgumentDefaultValue}'`;
}
const directiveArgumentDefaultValueChangedDangerousReason = 'Changing the default value for an argument may change the runtime behaviour of a field if it was never provided.';
function directiveArgumentDefaultValueChangedFromMeta(args) {
return {
criticality: {
level: change_js_1.CriticalityLevel.Dangerous,
reason: directiveArgumentDefaultValueChangedDangerousReason,
},
type: change_js_1.ChangeType.DirectiveArgumentDefaultValueChanged,
message: buildDirectiveArgumentDefaultValueChanged(args.meta),
path: `@${args.meta.directiveName}.${args.meta.directiveArgumentName}`,
meta: args.meta,
};
}
function directiveArgumentDefaultValueChanged(directive, oldArg, newArg) {
const meta = {
directiveName: directive.name,
directiveArgumentName: oldArg.name,
};
if (oldArg.defaultValue !== undefined) {
meta.oldDirectiveArgumentDefaultValue = (0, string_js_1.safeString)(oldArg.defaultValue);
}
if (newArg.defaultValue !== undefined) {
meta.newDirectiveArgumentDefaultValue = (0, string_js_1.safeString)(newArg.defaultValue);
}
return directiveArgumentDefaultValueChangedFromMeta({
type: change_js_1.ChangeType.DirectiveArgumentDefaultValueChanged,
meta,
});
}
function buildDirectiveArgumentTypeChangedMessage(args) {
return `Type for argument '${args.meta.directiveArgumentName}' on directive '${args.meta.directiveName}' changed from '${args.meta.oldDirectiveArgumentType}' to '${args.meta.newDirectiveArgumentType}'`;
}
const directiveArgumentTypeChangedNonBreakingReason = 'Changing an input field from non-null to null is considered non-breaking.';
function directiveArgumentTypeChangedFromMeta(args) {
return {
criticality: args.meta.isSafeDirectiveArgumentTypeChange
? {
level: change_js_1.CriticalityLevel.NonBreaking,
reason: directiveArgumentTypeChangedNonBreakingReason,
}
: {
level: change_js_1.CriticalityLevel.Breaking,
},
type: change_js_1.ChangeType.DirectiveArgumentTypeChanged,
message: buildDirectiveArgumentTypeChangedMessage(args),
path: `@${args.meta.directiveName}.${args.meta.directiveArgumentName}`,
meta: args.meta,
};
}
function directiveArgumentTypeChanged(directive, oldArg, newArg) {
return directiveArgumentTypeChangedFromMeta({
type: change_js_1.ChangeType.DirectiveArgumentTypeChanged,
meta: {
directiveName: directive.name,
directiveArgumentName: oldArg.name,
oldDirectiveArgumentType: oldArg.type.toString(),
newDirectiveArgumentType: newArg.type.toString(),
isSafeDirectiveArgumentTypeChange: (0, graphql_js_1.safeChangeForInputValue)(oldArg.type, newArg.type),
},
});
}
;