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 file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

findBreakingChanges: simplify checking of wrapped types

  • Loading branch information...
IvanGoncharov committed May 22, 2019
commit 9b993cfee0088f8f74b16a1806dd322317d270a4
@@ -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;
}

/**
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.