diff --git a/.changeset/bright-pumas-dance.md b/.changeset/bright-pumas-dance.md new file mode 100644 index 0000000000..88955530e6 --- /dev/null +++ b/.changeset/bright-pumas-dance.md @@ -0,0 +1,5 @@ +--- +"@graphql-inspector/core": patch +--- + +Escape single quotes in diff change messages for the rest of descriptions and deprecation reasons diff --git a/packages/core/src/diff/changes/argument.ts b/packages/core/src/diff/changes/argument.ts index 049147b433..b1a2cc93b7 100644 --- a/packages/core/src/diff/changes/argument.ts +++ b/packages/core/src/diff/changes/argument.ts @@ -1,6 +1,6 @@ import { GraphQLArgument, GraphQLField, GraphQLInterfaceType, GraphQLObjectType } from 'graphql'; import { safeChangeForInputValue } from '../../utils/graphql.js'; -import { safeString } from '../../utils/string.js'; +import { fmt, safeString } from '../../utils/string.js'; import { Change, ChangeType, @@ -13,7 +13,9 @@ import { function buildFieldArgumentDescriptionChangedMessage( args: FieldArgumentDescriptionChangedChange['meta'], ): string { - return `Description for argument '${args.argumentName}' on field '${args.typeName}.${args.fieldName}' changed from '${args.oldDescription}' to '${args.newDescription}'`; + const oldDesc = fmt(args.oldDescription ?? 'undefined'); + const newDesc = fmt(args.newDescription ?? 'undefined'); + return `Description for argument '${args.argumentName}' on field '${args.typeName}.${args.fieldName}' changed from '${oldDesc}' to '${newDesc}'`; } export function fieldArgumentDescriptionChangedFromMeta( diff --git a/packages/core/src/diff/changes/directive.ts b/packages/core/src/diff/changes/directive.ts index b2c6874b4c..9b6b89c51f 100644 --- a/packages/core/src/diff/changes/directive.ts +++ b/packages/core/src/diff/changes/directive.ts @@ -1,6 +1,6 @@ import { DirectiveLocationEnum, GraphQLArgument, GraphQLDirective, isNonNullType } from 'graphql'; import { safeChangeForInputValue } from '../../utils/graphql.js'; -import { safeString } from '../../utils/string.js'; +import { fmt, safeString } from '../../utils/string.js'; import { Change, ChangeType, @@ -82,9 +82,9 @@ export function directiveAdded( function buildDirectiveDescriptionChangedMessage( args: DirectiveDescriptionChangedChange['meta'], ): string { - return `Directive '${args.directiveName}' description changed from '${ - args.oldDirectiveDescription ?? 'undefined' - }' to '${args.newDirectiveDescription ?? 'undefined'}'`; + const oldDesc = fmt(args.oldDirectiveDescription ?? 'undefined'); + const newDesc = fmt(args.newDirectiveDescription ?? 'undefined'); + return `Directive '${args.directiveName}' description changed from '${oldDesc}' to '${newDesc}'`; } export function directiveDescriptionChangedFromMeta(args: DirectiveDescriptionChangedChange) { @@ -314,7 +314,9 @@ export function directiveArgumentRemoved( function buildDirectiveArgumentDescriptionChangedMessage( args: DirectiveArgumentDescriptionChangedChange['meta'], ): string { - return `Description for argument '${args.directiveArgumentName}' on directive '${args.directiveName}' changed from '${args.oldDirectiveArgumentDescription}' to '${args.newDirectiveArgumentDescription}'`; + const oldDesc = fmt(args.oldDirectiveArgumentDescription ?? 'undefined'); + const newDesc = fmt(args.newDirectiveArgumentDescription ?? 'undefined'); + return `Description for argument '${args.directiveArgumentName}' on directive '${args.directiveName}' changed from '${oldDesc}' to '${newDesc}'`; } export function directiveArgumentDescriptionChangedFromMeta( diff --git a/packages/core/src/diff/changes/field.ts b/packages/core/src/diff/changes/field.ts index 8eda935af0..f4a07e57dc 100644 --- a/packages/core/src/diff/changes/field.ts +++ b/packages/core/src/diff/changes/field.ts @@ -8,6 +8,7 @@ import { isNonNullType, } from 'graphql'; import { safeChangeForField } from '../../utils/graphql.js'; +import { fmt } from '../../utils/string.js'; import { Change, ChangeType, @@ -97,7 +98,9 @@ export function fieldAdded( } function buildFieldDescriptionChangedMessage(args: FieldDescriptionChangedChange['meta']) { - return `Field '${args.typeName}.${args.fieldName}' description changed from '${args.oldDescription}' to '${args.newDescription}'`; + const oldDesc = fmt(args.oldDescription || 'undefined'); + const newDesc = fmt(args.newDescription || 'undefined'); + return `Field '${args.typeName}.${args.fieldName}' description changed from '${oldDesc}' to '${newDesc}'`; } export function fieldDescriptionChangedFromMeta(args: FieldDescriptionChangedChange) { @@ -129,7 +132,8 @@ export function fieldDescriptionChanged( } function buildFieldDescriptionAddedMessage(args: FieldDescriptionAddedChange['meta']) { - return `Field '${args.typeName}.${args.fieldName}' has description '${args.addedDescription}'`; + const desc = fmt(args.addedDescription); + return `Field '${args.typeName}.${args.fieldName}' has description '${desc}'`; } export function fieldDescriptionAddedFromMeta(args: FieldDescriptionAddedChange) { @@ -249,7 +253,9 @@ export function fieldDeprecationRemoved( function buildFieldDeprecationReasonChangedMessage( args: FieldDeprecationReasonChangedChange['meta'], ) { - return `Deprecation reason on field '${args.typeName}.${args.fieldName}' has changed from '${args.oldDeprecationReason}' to '${args.newDeprecationReason}'`; + const oldReason = fmt(args.oldDeprecationReason); + const newReason = fmt(args.newDeprecationReason); + return `Deprecation reason on field '${args.typeName}.${args.fieldName}' has changed from '${oldReason}' to '${newReason}'`; } export function fieldDeprecationReasonChangedFromMeta(args: FieldDeprecationReasonChangedChange) { @@ -283,7 +289,8 @@ export function fieldDeprecationReasonChanged( } function buildFieldDeprecationReasonAddedMessage(args: FieldDeprecationReasonAddedChange['meta']) { - return `Field '${args.typeName}.${args.fieldName}' has deprecation reason '${args.addedDeprecationReason}'`; + const reason = fmt(args.addedDeprecationReason); + return `Field '${args.typeName}.${args.fieldName}' has deprecation reason '${reason}'`; } export function fieldDeprecationReasonAddedFromMeta(args: FieldDeprecationReasonAddedChange) { diff --git a/packages/core/src/diff/changes/input.ts b/packages/core/src/diff/changes/input.ts index 7b8012470d..e52d1386fe 100644 --- a/packages/core/src/diff/changes/input.ts +++ b/packages/core/src/diff/changes/input.ts @@ -1,7 +1,7 @@ import { GraphQLInputField, GraphQLInputObjectType, isNonNullType } from 'graphql'; import { safeChangeForInputValue } from '../../utils/graphql.js'; import { isDeprecated } from '../../utils/is-deprecated.js'; -import { safeString } from '../../utils/string.js'; +import { fmt, safeString } from '../../utils/string.js'; import { Change, ChangeType, @@ -95,7 +95,8 @@ export function inputFieldAdded( } function buildInputFieldDescriptionAddedMessage(args: InputFieldDescriptionAddedChange['meta']) { - return `Input field '${args.inputName}.${args.inputFieldName}' has description '${args.addedInputFieldDescription}'`; + const desc = fmt(args.addedInputFieldDescription); + return `Input field '${args.inputName}.${args.inputFieldName}' has description '${desc}'`; } export function inputFieldDescriptionAddedFromMeta(args: InputFieldDescriptionAddedChange) { @@ -127,7 +128,8 @@ export function inputFieldDescriptionAdded( function buildInputFieldDescriptionRemovedMessage( args: InputFieldDescriptionRemovedChange['meta'], ) { - return `Description '${args.removedDescription}' was removed from input field '${args.inputName}.${args.inputFieldName}'`; + const desc = fmt(args.removedDescription); + return `Description '${desc}' was removed from input field '${args.inputName}.${args.inputFieldName}'`; } export function inputFieldDescriptionRemovedFromMeta(args: InputFieldDescriptionRemovedChange) { @@ -159,7 +161,9 @@ export function inputFieldDescriptionRemoved( function buildInputFieldDescriptionChangedMessage( args: InputFieldDescriptionChangedChange['meta'], ) { - return `Input field '${args.inputName}.${args.inputFieldName}' description changed from '${args.oldInputFieldDescription}' to '${args.newInputFieldDescription}'`; + const oldDesc = fmt(args.oldInputFieldDescription); + const newDesc = fmt(args.newInputFieldDescription); + return `Input field '${args.inputName}.${args.inputFieldName}' description changed from '${oldDesc}' to '${newDesc}'`; } export function inputFieldDescriptionChangedFromMeta(args: InputFieldDescriptionChangedChange) { diff --git a/packages/core/src/diff/changes/type.ts b/packages/core/src/diff/changes/type.ts index 0d64b17ad6..716401bbc8 100644 --- a/packages/core/src/diff/changes/type.ts +++ b/packages/core/src/diff/changes/type.ts @@ -8,6 +8,7 @@ import { type GraphQLNamedType, } from 'graphql'; import { getKind } from '../../utils/graphql.js'; +import { fmt } from '../../utils/string.js'; import { Change, ChangeType, @@ -134,7 +135,9 @@ export function typeKindChanged( } function buildTypeDescriptionChangedMessage(args: TypeDescriptionChangedChange['meta']): string { - return `Description '${args.oldTypeDescription}' on type '${args.typeName}' has changed to '${args.newTypeDescription}'`; + const oldDesc = fmt(args.oldTypeDescription); + const newDesc = fmt(args.newTypeDescription); + return `Description '${oldDesc}' on type '${args.typeName}' has changed to '${newDesc}'`; } export function typeDescriptionChangedFromMeta(args: TypeDescriptionChangedChange) { @@ -164,7 +167,8 @@ export function typeDescriptionChanged( } function buildTypeDescriptionRemoved(args: TypeDescriptionRemovedChange['meta']): string { - return `Description '${args.removedTypeDescription}' was removed from object type '${args.typeName}'`; + const desc = fmt(args.removedTypeDescription); + return `Description '${desc}' was removed from object type '${args.typeName}'`; } export function typeDescriptionRemovedFromMeta(args: TypeDescriptionRemovedChange) { @@ -192,7 +196,8 @@ export function typeDescriptionRemoved( } function buildTypeDescriptionAddedMessage(args: TypeDescriptionAddedChange['meta']): string { - return `Object type '${args.typeName}' has description '${args.addedTypeDescription}'`; + const desc = fmt(args.addedTypeDescription); + return `Object type '${args.typeName}' has description '${desc}'`; } export function typeDescriptionAddedFromMeta(args: TypeDescriptionAddedChange) {