UNPKG

@graphql-inspector/core

Version:

Tooling for GraphQL. Compare GraphQL Schemas, check documents, find breaking changes, find similar types.

353 lines (352 loc) • 14.3 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.fieldRemovedFromMeta = fieldRemovedFromMeta; exports.fieldRemoved = fieldRemoved; exports.fieldAddedFromMeta = fieldAddedFromMeta; exports.fieldAdded = fieldAdded; exports.fieldDescriptionChangedFromMeta = fieldDescriptionChangedFromMeta; exports.fieldDescriptionChanged = fieldDescriptionChanged; exports.fieldDescriptionAddedFromMeta = fieldDescriptionAddedFromMeta; exports.fieldDescriptionAdded = fieldDescriptionAdded; exports.fieldDescriptionRemovedFromMeta = fieldDescriptionRemovedFromMeta; exports.fieldDescriptionRemoved = fieldDescriptionRemoved; exports.fieldDeprecationAddedFromMeta = fieldDeprecationAddedFromMeta; exports.fieldDeprecationAdded = fieldDeprecationAdded; exports.fieldDeprecationRemovedFromMeta = fieldDeprecationRemovedFromMeta; exports.fieldDeprecationRemoved = fieldDeprecationRemoved; exports.fieldDeprecationReasonChangedFromMeta = fieldDeprecationReasonChangedFromMeta; exports.fieldDeprecationReasonChanged = fieldDeprecationReasonChanged; exports.fieldDeprecationReasonAddedFromMeta = fieldDeprecationReasonAddedFromMeta; exports.fieldDeprecationReasonAdded = fieldDeprecationReasonAdded; exports.fieldDeprecationReasonRemovedFromMeta = fieldDeprecationReasonRemovedFromMeta; exports.fieldDeprecationReasonRemoved = fieldDeprecationReasonRemoved; exports.fieldTypeChangedFromMeta = fieldTypeChangedFromMeta; exports.fieldTypeChanged = fieldTypeChanged; exports.fieldArgumentAddedFromMeta = fieldArgumentAddedFromMeta; exports.fieldArgumentAdded = fieldArgumentAdded; exports.fieldArgumentRemovedFromMeta = fieldArgumentRemovedFromMeta; exports.fieldArgumentRemoved = fieldArgumentRemoved; const graphql_1 = require("graphql"); const graphql_js_1 = require("../../utils/graphql.js"); const change_js_1 = require("./change.js"); function buildFieldRemovedMessage(args) { return `Field '${args.removedFieldName}' ${args.isRemovedFieldDeprecated ? '(deprecated) ' : ''}was removed from ${args.typeType} '${args.typeName}'`; } function fieldRemovedFromMeta(args) { return { type: change_js_1.ChangeType.FieldRemoved, criticality: { level: change_js_1.CriticalityLevel.Breaking, reason: args.meta.isRemovedFieldDeprecated ? `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. This applies to removed union fields as well, since removal breaks client operations that contain fragments that reference the removed type through direct (... on RemovedType) or indirect means such as __typename in the consumers.`, }, message: buildFieldRemovedMessage(args.meta), meta: args.meta, path: [args.meta.typeName, args.meta.removedFieldName].join('.'), }; } function fieldRemoved(type, field) { const entity = (0, graphql_1.isInterfaceType)(type) ? 'interface' : 'object type'; return fieldRemovedFromMeta({ type: change_js_1.ChangeType.FieldRemoved, meta: { typeName: type.name, removedFieldName: field.name, isRemovedFieldDeprecated: field.deprecationReason != null, typeType: entity, }, }); } function buildFieldAddedMessage(args) { return `Field '${args.addedFieldName}' was added to ${args.typeType} '${args.typeName}'`; } function fieldAddedFromMeta(args) { return { type: change_js_1.ChangeType.FieldAdded, criticality: { level: change_js_1.CriticalityLevel.NonBreaking, }, message: buildFieldAddedMessage(args.meta), meta: args.meta, path: [args.meta.typeName, args.meta.addedFieldName].join('.'), }; } function fieldAdded(type, field) { const entity = (0, graphql_1.isInterfaceType)(type) ? 'interface' : 'object type'; return fieldAddedFromMeta({ type: change_js_1.ChangeType.FieldAdded, meta: { typeName: type.name, addedFieldName: field.name, typeType: entity, }, }); } function buildFieldDescriptionChangedMessage(args) { return `Field '${args.typeName}.${args.fieldName}' description changed from '${args.oldDescription}' to '${args.newDescription}'`; } function fieldDescriptionChangedFromMeta(args) { return { type: change_js_1.ChangeType.FieldDescriptionChanged, criticality: { level: change_js_1.CriticalityLevel.NonBreaking, }, message: buildFieldDescriptionChangedMessage(args.meta), meta: args.meta, path: [args.meta.typeName, args.meta.fieldName].join('.'), }; } function fieldDescriptionChanged(type, oldField, newField) { return fieldDescriptionChangedFromMeta({ type: change_js_1.ChangeType.FieldDescriptionChanged, meta: { fieldName: oldField.name, typeName: type.name, oldDescription: oldField.description ?? '', newDescription: newField.description ?? '', }, }); } function buildFieldDescriptionAddedMessage(args) { return `Field '${args.typeName}.${args.fieldName}' has description '${args.addedDescription}'`; } function fieldDescriptionAddedFromMeta(args) { return { type: change_js_1.ChangeType.FieldDescriptionAdded, criticality: { level: change_js_1.CriticalityLevel.NonBreaking, }, message: buildFieldDescriptionAddedMessage(args.meta), meta: args.meta, path: [args.meta.typeName, args.meta.fieldName].join('.'), }; } function fieldDescriptionAdded(type, field) { return fieldDescriptionAddedFromMeta({ type: change_js_1.ChangeType.FieldDescriptionAdded, meta: { typeName: type.name, fieldName: field.name, addedDescription: field.description ?? '', }, }); } function buildFieldDescriptionRemovedMessage(args) { return `Description was removed from field '${args.typeName}.${args.fieldName}'`; } function fieldDescriptionRemovedFromMeta(args) { return { type: change_js_1.ChangeType.FieldDescriptionRemoved, criticality: { level: change_js_1.CriticalityLevel.NonBreaking, }, message: buildFieldDescriptionRemovedMessage(args.meta), meta: args.meta, path: [args.meta.typeName, args.meta.fieldName].join('.'), }; } function fieldDescriptionRemoved(type, field) { return fieldDescriptionRemovedFromMeta({ type: change_js_1.ChangeType.FieldDescriptionRemoved, meta: { typeName: type.name, fieldName: field.name, }, }); } function buildFieldDeprecatedAddedMessage(args) { return `Field '${args.typeName}.${args.fieldName}' is deprecated`; } function fieldDeprecationAddedFromMeta(args) { return { type: change_js_1.ChangeType.FieldDeprecationAdded, criticality: { level: change_js_1.CriticalityLevel.NonBreaking, }, message: buildFieldDeprecatedAddedMessage(args.meta), meta: args.meta, path: [args.meta.typeName, args.meta.fieldName].join('.'), }; } function fieldDeprecationAdded(type, field) { return fieldDeprecationAddedFromMeta({ type: change_js_1.ChangeType.FieldDeprecationAdded, meta: { typeName: type.name, fieldName: field.name, }, }); } function fieldDeprecationRemovedFromMeta(args) { return { type: change_js_1.ChangeType.FieldDeprecationRemoved, criticality: { level: change_js_1.CriticalityLevel.Dangerous, }, message: `Field '${args.meta.typeName}.${args.meta.fieldName}' is no longer deprecated`, meta: args.meta, path: [args.meta.typeName, args.meta.fieldName].join('.'), }; } function fieldDeprecationRemoved(type, field) { return fieldDeprecationRemovedFromMeta({ type: change_js_1.ChangeType.FieldDeprecationRemoved, meta: { fieldName: field.name, typeName: type.name, }, }); } function buildFieldDeprecationReasonChangedMessage(args) { return `Deprecation reason on field '${args.typeName}.${args.fieldName}' has changed from '${args.oldDeprecationReason}' to '${args.newDeprecationReason}'`; } function fieldDeprecationReasonChangedFromMeta(args) { return { type: change_js_1.ChangeType.FieldDeprecationReasonChanged, criticality: { level: change_js_1.CriticalityLevel.NonBreaking, }, message: buildFieldDeprecationReasonChangedMessage(args.meta), meta: args.meta, path: [args.meta.typeName, args.meta.fieldName].join('.'), }; } function fieldDeprecationReasonChanged(type, oldField, newField) { return fieldDeprecationReasonChangedFromMeta({ type: change_js_1.ChangeType.FieldDeprecationReasonChanged, meta: { fieldName: newField.name, typeName: type.name, newDeprecationReason: newField.deprecationReason ?? '', oldDeprecationReason: oldField.deprecationReason ?? '', }, }); } function buildFieldDeprecationReasonAddedMessage(args) { return `Field '${args.typeName}.${args.fieldName}' has deprecation reason '${args.addedDeprecationReason}'`; } function fieldDeprecationReasonAddedFromMeta(args) { return { type: change_js_1.ChangeType.FieldDeprecationReasonAdded, criticality: { level: change_js_1.CriticalityLevel.NonBreaking, }, message: buildFieldDeprecationReasonAddedMessage(args.meta), meta: args.meta, path: [args.meta.typeName, args.meta.fieldName].join('.'), }; } function fieldDeprecationReasonAdded(type, field) { return fieldDeprecationReasonAddedFromMeta({ type: change_js_1.ChangeType.FieldDeprecationReasonAdded, meta: { typeName: type.name, fieldName: field.name, addedDeprecationReason: field.deprecationReason ?? '', }, }); } function fieldDeprecationReasonRemovedFromMeta(args) { return { type: change_js_1.ChangeType.FieldDeprecationReasonRemoved, criticality: { level: change_js_1.CriticalityLevel.NonBreaking, }, message: `Deprecation reason was removed from field '${args.meta.typeName}.${args.meta.fieldName}'`, meta: args.meta, path: [args.meta.typeName, args.meta.fieldName].join('.'), }; } function fieldDeprecationReasonRemoved(type, field) { return fieldDeprecationReasonRemovedFromMeta({ type: change_js_1.ChangeType.FieldDeprecationReasonRemoved, meta: { typeName: type.name, fieldName: field.name, }, }); } function buildFieldTypeChangedMessage(args) { return `Field '${args.meta.typeName}.${args.meta.fieldName}' changed type from '${args.meta.oldFieldType}' to '${args.meta.newFieldType}'`; } function fieldTypeChangedFromMeta(args) { return { type: change_js_1.ChangeType.FieldTypeChanged, criticality: { level: args.meta.isSafeFieldTypeChange ? change_js_1.CriticalityLevel.NonBreaking : change_js_1.CriticalityLevel.Breaking, }, message: buildFieldTypeChangedMessage(args), meta: args.meta, path: [args.meta.typeName, args.meta.fieldName].join('.'), }; } function fieldTypeChanged(type, oldField, newField) { return fieldTypeChangedFromMeta({ type: change_js_1.ChangeType.FieldTypeChanged, meta: { typeName: type.name, fieldName: oldField.name, oldFieldType: oldField.type.toString(), newFieldType: newField.type.toString(), isSafeFieldTypeChange: (0, graphql_js_1.safeChangeForField)(oldField.type, newField.type), }, }); } function buildFieldArgumentAddedMessage(args) { return `Argument '${args.addedArgumentName}: ${args.addedArgumentType}'${args.hasDefaultValue ? ' (with default value) ' : ' '}added to field '${args.typeName}.${args.fieldName}'`; } function fieldArgumentAddedFromMeta(args) { return { type: change_js_1.ChangeType.FieldArgumentAdded, criticality: { level: args.meta.isAddedFieldArgumentBreaking ? change_js_1.CriticalityLevel.Breaking : change_js_1.CriticalityLevel.Dangerous, }, message: buildFieldArgumentAddedMessage(args.meta), meta: args.meta, path: [args.meta.typeName, args.meta.fieldName, args.meta.addedArgumentName].join('.'), }; } function fieldArgumentAdded(type, field, arg) { const isBreaking = (0, graphql_1.isNonNullType)(arg.type) && typeof arg.defaultValue === 'undefined'; return fieldArgumentAddedFromMeta({ type: change_js_1.ChangeType.FieldArgumentAdded, meta: { typeName: type.name, fieldName: field.name, addedArgumentName: arg.name, addedArgumentType: arg.type.toString(), hasDefaultValue: arg.defaultValue != null, isAddedFieldArgumentBreaking: isBreaking, }, }); } function buildFieldArgumentRemovedMessage(args) { return `Argument '${args.meta.removedFieldArgumentName}: ${args.meta.removedFieldType}' was removed from field '${args.meta.typeName}.${args.meta.fieldName}'`; } function fieldArgumentRemovedFromMeta(args) { return { type: change_js_1.ChangeType.FieldArgumentRemoved, criticality: { level: change_js_1.CriticalityLevel.Breaking, }, message: buildFieldArgumentRemovedMessage(args), meta: args.meta, path: [args.meta.typeName, args.meta.fieldName, args.meta.removedFieldArgumentName].join('.'), }; } function fieldArgumentRemoved(type, field, arg) { return fieldArgumentRemovedFromMeta({ type: change_js_1.ChangeType.FieldArgumentRemoved, meta: { typeName: type.name, fieldName: field.name, removedFieldArgumentName: arg.name, removedFieldType: arg.type.toString(), }, }); }