Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

findBreakingChanges: simplify checking of wrapped types #1898

Merged
merged 1 commit into from May 22, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
36 changes: 19 additions & 17 deletions src/utilities/findBreakingChanges.js
Expand Up @@ -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) &&
Expand All @@ -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
Expand All @@ -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;
}

/**
Expand Down