Skip to content

Commit 1e9f99e

Browse files
committed
fix: escape single quotes in descriptions and deprecation reasons
1 parent b3bac0e commit 1e9f99e

File tree

6 files changed

+43
-18
lines changed

6 files changed

+43
-18
lines changed

.changeset/bright-pumas-dance.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@graphql-inspector/core": patch
3+
---
4+
5+
Escape single quotes in diff change messages for the rest of descriptions and deprecation reasons

packages/core/src/diff/changes/argument.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { GraphQLArgument, GraphQLField, GraphQLInterfaceType, GraphQLObjectType } from 'graphql';
22
import { safeChangeForInputValue } from '../../utils/graphql.js';
3-
import { safeString } from '../../utils/string.js';
3+
import { fmt, safeString } from '../../utils/string.js';
44
import {
55
Change,
66
ChangeType,
@@ -13,7 +13,9 @@ import {
1313
function buildFieldArgumentDescriptionChangedMessage(
1414
args: FieldArgumentDescriptionChangedChange['meta'],
1515
): string {
16-
return `Description for argument '${args.argumentName}' on field '${args.typeName}.${args.fieldName}' changed from '${args.oldDescription}' to '${args.newDescription}'`;
16+
const oldDesc = fmt(args.oldDescription ?? 'undefined');
17+
const newDesc = fmt(args.newDescription ?? 'undefined');
18+
return `Description for argument '${args.argumentName}' on field '${args.typeName}.${args.fieldName}' changed from '${oldDesc}' to '${newDesc}'`;
1719
}
1820

1921
export function fieldArgumentDescriptionChangedFromMeta(

packages/core/src/diff/changes/directive.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { DirectiveLocationEnum, GraphQLArgument, GraphQLDirective, isNonNullType } from 'graphql';
22
import { safeChangeForInputValue } from '../../utils/graphql.js';
3-
import { safeString } from '../../utils/string.js';
3+
import { fmt, safeString } from '../../utils/string.js';
44
import {
55
Change,
66
ChangeType,
@@ -82,9 +82,9 @@ export function directiveAdded(
8282
function buildDirectiveDescriptionChangedMessage(
8383
args: DirectiveDescriptionChangedChange['meta'],
8484
): string {
85-
return `Directive '${args.directiveName}' description changed from '${
86-
args.oldDirectiveDescription ?? 'undefined'
87-
}' to '${args.newDirectiveDescription ?? 'undefined'}'`;
85+
const oldDesc = fmt(args.oldDirectiveDescription ?? 'undefined');
86+
const newDesc = fmt(args.newDirectiveDescription ?? 'undefined');
87+
return `Directive '${args.directiveName}' description changed from '${oldDesc}' to '${newDesc}'`;
8888
}
8989

9090
export function directiveDescriptionChangedFromMeta(args: DirectiveDescriptionChangedChange) {
@@ -314,7 +314,9 @@ export function directiveArgumentRemoved(
314314
function buildDirectiveArgumentDescriptionChangedMessage(
315315
args: DirectiveArgumentDescriptionChangedChange['meta'],
316316
): string {
317-
return `Description for argument '${args.directiveArgumentName}' on directive '${args.directiveName}' changed from '${args.oldDirectiveArgumentDescription}' to '${args.newDirectiveArgumentDescription}'`;
317+
const oldDesc = fmt(args.oldDirectiveArgumentDescription ?? 'undefined');
318+
const newDesc = fmt(args.newDirectiveArgumentDescription ?? 'undefined');
319+
return `Description for argument '${args.directiveArgumentName}' on directive '${args.directiveName}' changed from '${oldDesc}' to '${newDesc}'`;
318320
}
319321

320322
export function directiveArgumentDescriptionChangedFromMeta(

packages/core/src/diff/changes/field.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
isNonNullType,
99
} from 'graphql';
1010
import { safeChangeForField } from '../../utils/graphql.js';
11+
import { fmt } from '../../utils/string.js';
1112
import {
1213
Change,
1314
ChangeType,
@@ -97,7 +98,9 @@ export function fieldAdded(
9798
}
9899

99100
function buildFieldDescriptionChangedMessage(args: FieldDescriptionChangedChange['meta']) {
100-
return `Field '${args.typeName}.${args.fieldName}' description changed from '${args.oldDescription}' to '${args.newDescription}'`;
101+
const oldDesc = fmt(args.oldDescription || 'undefined');
102+
const newDesc = fmt(args.newDescription || 'undefined');
103+
return `Field '${args.typeName}.${args.fieldName}' description changed from '${oldDesc}' to '${newDesc}'`;
101104
}
102105

103106
export function fieldDescriptionChangedFromMeta(args: FieldDescriptionChangedChange) {
@@ -129,7 +132,8 @@ export function fieldDescriptionChanged(
129132
}
130133

131134
function buildFieldDescriptionAddedMessage(args: FieldDescriptionAddedChange['meta']) {
132-
return `Field '${args.typeName}.${args.fieldName}' has description '${args.addedDescription}'`;
135+
const desc = fmt(args.addedDescription);
136+
return `Field '${args.typeName}.${args.fieldName}' has description '${desc}'`;
133137
}
134138

135139
export function fieldDescriptionAddedFromMeta(args: FieldDescriptionAddedChange) {
@@ -249,7 +253,9 @@ export function fieldDeprecationRemoved(
249253
function buildFieldDeprecationReasonChangedMessage(
250254
args: FieldDeprecationReasonChangedChange['meta'],
251255
) {
252-
return `Deprecation reason on field '${args.typeName}.${args.fieldName}' has changed from '${args.oldDeprecationReason}' to '${args.newDeprecationReason}'`;
256+
const oldReason = fmt(args.oldDeprecationReason);
257+
const newReason = fmt(args.newDeprecationReason);
258+
return `Deprecation reason on field '${args.typeName}.${args.fieldName}' has changed from '${oldReason}' to '${newReason}'`;
253259
}
254260

255261
export function fieldDeprecationReasonChangedFromMeta(args: FieldDeprecationReasonChangedChange) {
@@ -283,7 +289,8 @@ export function fieldDeprecationReasonChanged(
283289
}
284290

285291
function buildFieldDeprecationReasonAddedMessage(args: FieldDeprecationReasonAddedChange['meta']) {
286-
return `Field '${args.typeName}.${args.fieldName}' has deprecation reason '${args.addedDeprecationReason}'`;
292+
const reason = fmt(args.addedDeprecationReason);
293+
return `Field '${args.typeName}.${args.fieldName}' has deprecation reason '${reason}'`;
287294
}
288295

289296
export function fieldDeprecationReasonAddedFromMeta(args: FieldDeprecationReasonAddedChange) {

packages/core/src/diff/changes/input.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { GraphQLInputField, GraphQLInputObjectType, isNonNullType } from 'graphql';
22
import { safeChangeForInputValue } from '../../utils/graphql.js';
33
import { isDeprecated } from '../../utils/is-deprecated.js';
4-
import { safeString } from '../../utils/string.js';
4+
import { fmt, safeString } from '../../utils/string.js';
55
import {
66
Change,
77
ChangeType,
@@ -95,7 +95,8 @@ export function inputFieldAdded(
9595
}
9696

9797
function buildInputFieldDescriptionAddedMessage(args: InputFieldDescriptionAddedChange['meta']) {
98-
return `Input field '${args.inputName}.${args.inputFieldName}' has description '${args.addedInputFieldDescription}'`;
98+
const desc = fmt(args.addedInputFieldDescription);
99+
return `Input field '${args.inputName}.${args.inputFieldName}' has description '${desc}'`;
99100
}
100101

101102
export function inputFieldDescriptionAddedFromMeta(args: InputFieldDescriptionAddedChange) {
@@ -127,7 +128,8 @@ export function inputFieldDescriptionAdded(
127128
function buildInputFieldDescriptionRemovedMessage(
128129
args: InputFieldDescriptionRemovedChange['meta'],
129130
) {
130-
return `Description '${args.removedDescription}' was removed from input field '${args.inputName}.${args.inputFieldName}'`;
131+
const desc = fmt(args.removedDescription);
132+
return `Description '${desc}' was removed from input field '${args.inputName}.${args.inputFieldName}'`;
131133
}
132134

133135
export function inputFieldDescriptionRemovedFromMeta(args: InputFieldDescriptionRemovedChange) {
@@ -159,7 +161,9 @@ export function inputFieldDescriptionRemoved(
159161
function buildInputFieldDescriptionChangedMessage(
160162
args: InputFieldDescriptionChangedChange['meta'],
161163
) {
162-
return `Input field '${args.inputName}.${args.inputFieldName}' description changed from '${args.oldInputFieldDescription}' to '${args.newInputFieldDescription}'`;
164+
const oldDesc = fmt(args.oldInputFieldDescription);
165+
const newDesc = fmt(args.newInputFieldDescription);
166+
return `Input field '${args.inputName}.${args.inputFieldName}' description changed from '${oldDesc}' to '${newDesc}'`;
163167
}
164168

165169
export function inputFieldDescriptionChangedFromMeta(args: InputFieldDescriptionChangedChange) {

packages/core/src/diff/changes/type.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
type GraphQLNamedType,
99
} from 'graphql';
1010
import { getKind } from '../../utils/graphql.js';
11+
import { fmt } from '../../utils/string.js';
1112
import {
1213
Change,
1314
ChangeType,
@@ -134,7 +135,9 @@ export function typeKindChanged(
134135
}
135136

136137
function buildTypeDescriptionChangedMessage(args: TypeDescriptionChangedChange['meta']): string {
137-
return `Description '${args.oldTypeDescription}' on type '${args.typeName}' has changed to '${args.newTypeDescription}'`;
138+
const oldDesc = fmt(args.oldTypeDescription);
139+
const newDesc = fmt(args.newTypeDescription);
140+
return `Description '${oldDesc}' on type '${args.typeName}' has changed to '${newDesc}'`;
138141
}
139142

140143
export function typeDescriptionChangedFromMeta(args: TypeDescriptionChangedChange) {
@@ -164,7 +167,8 @@ export function typeDescriptionChanged(
164167
}
165168

166169
function buildTypeDescriptionRemoved(args: TypeDescriptionRemovedChange['meta']): string {
167-
return `Description '${args.removedTypeDescription}' was removed from object type '${args.typeName}'`;
170+
const desc = fmt(args.removedTypeDescription);
171+
return `Description '${desc}' was removed from object type '${args.typeName}'`;
168172
}
169173

170174
export function typeDescriptionRemovedFromMeta(args: TypeDescriptionRemovedChange) {
@@ -192,7 +196,8 @@ export function typeDescriptionRemoved(
192196
}
193197

194198
function buildTypeDescriptionAddedMessage(args: TypeDescriptionAddedChange['meta']): string {
195-
return `Object type '${args.typeName}' has description '${args.addedTypeDescription}'`;
199+
const desc = fmt(args.addedTypeDescription);
200+
return `Object type '${args.typeName}' has description '${desc}'`;
196201
}
197202

198203
export function typeDescriptionAddedFromMeta(args: TypeDescriptionAddedChange) {

0 commit comments

Comments
 (0)