Skip to content

Commit 4bff6d8

Browse files
findBreakingChanges: simplify checking of wrapped types (#1898)
1 parent ec020fb commit 4bff6d8

File tree

1 file changed

+19
-17
lines changed

1 file changed

+19
-17
lines changed

src/utilities/findBreakingChanges.js

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -437,15 +437,7 @@ function isChangeSafeForObjectOrInterfaceField(
437437
oldType: GraphQLType,
438438
newType: GraphQLType,
439439
): boolean {
440-
if (isNamedType(oldType)) {
441-
return (
442-
// if they're both named types, see if their names are equivalent
443-
(isNamedType(newType) && oldType.name === newType.name) ||
444-
// moving from nullable to non-null of the same underlying type is safe
445-
(isNonNullType(newType) &&
446-
isChangeSafeForObjectOrInterfaceField(oldType, newType.ofType))
447-
);
448-
} else if (isListType(oldType)) {
440+
if (isListType(oldType)) {
449441
return (
450442
// if they're both lists, make sure the underlying types are compatible
451443
(isListType(newType) &&
@@ -457,30 +449,38 @@ function isChangeSafeForObjectOrInterfaceField(
457449
(isNonNullType(newType) &&
458450
isChangeSafeForObjectOrInterfaceField(oldType, newType.ofType))
459451
);
460-
} else if (isNonNullType(oldType)) {
452+
}
453+
454+
if (isNonNullType(oldType)) {
461455
// if they're both non-null, make sure the underlying types are compatible
462456
return (
463457
isNonNullType(newType) &&
464458
isChangeSafeForObjectOrInterfaceField(oldType.ofType, newType.ofType)
465459
);
466460
}
467-
return false;
461+
462+
return (
463+
// if they're both named types, see if their names are equivalent
464+
(isNamedType(newType) && oldType.name === newType.name) ||
465+
// moving from nullable to non-null of the same underlying type is safe
466+
(isNonNullType(newType) &&
467+
isChangeSafeForObjectOrInterfaceField(oldType, newType.ofType))
468+
);
468469
}
469470

470471
function isChangeSafeForInputObjectFieldOrFieldArg(
471472
oldType: GraphQLType,
472473
newType: GraphQLType,
473474
): boolean {
474-
if (isNamedType(oldType)) {
475-
// if they're both named types, see if their names are equivalent
476-
return isNamedType(newType) && oldType.name === newType.name;
477-
} else if (isListType(oldType)) {
475+
if (isListType(oldType)) {
478476
// if they're both lists, make sure the underlying types are compatible
479477
return (
480478
isListType(newType) &&
481479
isChangeSafeForInputObjectFieldOrFieldArg(oldType.ofType, newType.ofType)
482480
);
483-
} else if (isNonNullType(oldType)) {
481+
}
482+
483+
if (isNonNullType(oldType)) {
484484
return (
485485
// if they're both non-null, make sure the underlying types are
486486
// compatible
@@ -494,7 +494,9 @@ function isChangeSafeForInputObjectFieldOrFieldArg(
494494
isChangeSafeForInputObjectFieldOrFieldArg(oldType.ofType, newType))
495495
);
496496
}
497-
return false;
497+
498+
// if they're both named types, see if their names are equivalent
499+
return isNamedType(newType) && oldType.name === newType.name;
498500
}
499501

500502
/**

0 commit comments

Comments
 (0)