@graphql-inspector/core
Version:
Tooling for GraphQL. Compare GraphQL Schemas, check documents, find breaking changes, find similar types.
56 lines (55 loc) • 2.31 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.objectTypeInterfaceAddedFromMeta = objectTypeInterfaceAddedFromMeta;
exports.objectTypeInterfaceAdded = objectTypeInterfaceAdded;
exports.objectTypeInterfaceRemovedFromMeta = objectTypeInterfaceRemovedFromMeta;
exports.objectTypeInterfaceRemoved = objectTypeInterfaceRemoved;
const change_js_1 = require("./change.js");
function buildObjectTypeInterfaceAddedMessage(args) {
return `'${args.objectTypeName}' object implements '${args.addedInterfaceName}' interface`;
}
function objectTypeInterfaceAddedFromMeta(args) {
return {
type: change_js_1.ChangeType.ObjectTypeInterfaceAdded,
criticality: {
level: change_js_1.CriticalityLevel.Dangerous,
reason: 'Adding an interface to an object type may break existing clients that were not programming defensively against a new possible type.',
},
message: buildObjectTypeInterfaceAddedMessage(args.meta),
meta: args.meta,
path: args.meta.objectTypeName,
};
}
function objectTypeInterfaceAdded(iface, type) {
return objectTypeInterfaceAddedFromMeta({
type: change_js_1.ChangeType.ObjectTypeInterfaceAdded,
meta: {
objectTypeName: type.name,
addedInterfaceName: iface.name,
},
});
}
function buildObjectTypeInterfaceRemovedMessage(args) {
return `'${args.objectTypeName}' object type no longer implements '${args.removedInterfaceName}' interface`;
}
function objectTypeInterfaceRemovedFromMeta(args) {
return {
type: change_js_1.ChangeType.ObjectTypeInterfaceRemoved,
criticality: {
level: change_js_1.CriticalityLevel.Breaking,
reason: 'Removing an interface from an object type can cause existing queries that use this in a fragment spread to error.',
},
message: buildObjectTypeInterfaceRemovedMessage(args.meta),
meta: args.meta,
path: args.meta.objectTypeName,
};
}
function objectTypeInterfaceRemoved(iface, type) {
return objectTypeInterfaceRemovedFromMeta({
type: change_js_1.ChangeType.ObjectTypeInterfaceRemoved,
meta: {
objectTypeName: type.name,
removedInterfaceName: iface.name,
},
});
}
;