From 4bff6d8af28cf58c5338f5a8d63c429bdf5f577e Mon Sep 17 00:00:00 2001 From: Ivan Goncharov Date: Wed, 22 May 2019 20:01:59 +0300 Subject: [PATCH] findBreakingChanges: simplify checking of wrapped types (#1898) --- src/utilities/findBreakingChanges.js | 36 +++++++++++++++------------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/src/utilities/findBreakingChanges.js b/src/utilities/findBreakingChanges.js index 54b9ec2949..6e74d13c57 100644 --- a/src/utilities/findBreakingChanges.js +++ b/src/utilities/findBreakingChanges.js @@ -437,15 +437,7 @@ function isChangeSafeForObjectOrInterfaceField( oldType: GraphQLType, newType: GraphQLType, ): boolean { - if (isNamedType(oldType)) { - return ( - // if they're both named types, see if their names are equivalent - (isNamedType(newType) && oldType.name === newType.name) || - // moving from nullable to non-null of the same underlying type is safe - (isNonNullType(newType) && - isChangeSafeForObjectOrInterfaceField(oldType, newType.ofType)) - ); - } else if (isListType(oldType)) { + if (isListType(oldType)) { return ( // if they're both lists, make sure the underlying types are compatible (isListType(newType) && @@ -457,30 +449,38 @@ function isChangeSafeForObjectOrInterfaceField( (isNonNullType(newType) && isChangeSafeForObjectOrInterfaceField(oldType, newType.ofType)) ); - } else if (isNonNullType(oldType)) { + } + + if (isNonNullType(oldType)) { // if they're both non-null, make sure the underlying types are compatible return ( isNonNullType(newType) && isChangeSafeForObjectOrInterfaceField(oldType.ofType, newType.ofType) ); } - return false; + + return ( + // if they're both named types, see if their names are equivalent + (isNamedType(newType) && oldType.name === newType.name) || + // moving from nullable to non-null of the same underlying type is safe + (isNonNullType(newType) && + isChangeSafeForObjectOrInterfaceField(oldType, newType.ofType)) + ); } function isChangeSafeForInputObjectFieldOrFieldArg( oldType: GraphQLType, newType: GraphQLType, ): boolean { - if (isNamedType(oldType)) { - // if they're both named types, see if their names are equivalent - return isNamedType(newType) && oldType.name === newType.name; - } else if (isListType(oldType)) { + if (isListType(oldType)) { // if they're both lists, make sure the underlying types are compatible return ( isListType(newType) && isChangeSafeForInputObjectFieldOrFieldArg(oldType.ofType, newType.ofType) ); - } else if (isNonNullType(oldType)) { + } + + if (isNonNullType(oldType)) { return ( // if they're both non-null, make sure the underlying types are // compatible @@ -494,7 +494,9 @@ function isChangeSafeForInputObjectFieldOrFieldArg( isChangeSafeForInputObjectFieldOrFieldArg(oldType.ofType, newType)) ); } - return false; + + // if they're both named types, see if their names are equivalent + return isNamedType(newType) && oldType.name === newType.name; } /**