Skip to content

Commit f4af437

Browse files
committed
find_breaking_changes: simplify checking of wrapped types
Replicates graphql/graphql-js@4bff6d8
1 parent f8f4bed commit f4af437

File tree

1 file changed

+26
-28
lines changed

1 file changed

+26
-28
lines changed

graphql/utilities/find_breaking_changes.py

Lines changed: 26 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -428,20 +428,7 @@ def find_fields_that_changed_type_on_input_object_types(
428428
def is_change_safe_for_object_or_interface_field(
429429
old_type: GraphQLType, new_type: GraphQLType
430430
) -> bool:
431-
if is_named_type(old_type):
432-
return (
433-
# if they're both named types, see if their names are equivalent
434-
is_named_type(new_type)
435-
and cast(GraphQLNamedType, old_type).name
436-
== cast(GraphQLNamedType, new_type).name
437-
) or (
438-
# moving from nullable to non-null of same underlying type is safe
439-
is_non_null_type(new_type)
440-
and is_change_safe_for_object_or_interface_field(
441-
old_type, cast(GraphQLNonNull, new_type).of_type
442-
)
443-
)
444-
elif is_list_type(old_type):
431+
if is_list_type(old_type):
445432
return (
446433
# if they're both lists, make sure underlying types are compatible
447434
is_list_type(new_type)
@@ -455,37 +442,43 @@ def is_change_safe_for_object_or_interface_field(
455442
old_type, cast(GraphQLNonNull, new_type).of_type
456443
)
457444
)
458-
elif is_non_null_type(old_type):
445+
446+
if is_non_null_type(old_type):
459447
# if they're both non-null, make sure underlying types are compatible
460448
return is_non_null_type(
461449
new_type
462450
) and is_change_safe_for_object_or_interface_field(
463451
cast(GraphQLNonNull, old_type).of_type,
464452
cast(GraphQLNonNull, new_type).of_type,
465453
)
466-
else:
467-
return False
454+
455+
return (
456+
# if they're both named types, see if their names are equivalent
457+
is_named_type(new_type)
458+
and cast(GraphQLNamedType, old_type).name
459+
== cast(GraphQLNamedType, new_type).name
460+
) or (
461+
# moving from nullable to non-null of same underlying type is safe
462+
is_non_null_type(new_type)
463+
and is_change_safe_for_object_or_interface_field(
464+
old_type, cast(GraphQLNonNull, new_type).of_type
465+
)
466+
)
468467

469468

470469
def is_change_safe_for_input_object_field_or_field_arg(
471470
old_type: GraphQLType, new_type: GraphQLType
472471
) -> bool:
473-
if is_named_type(old_type):
474-
return (
475-
# if they're both named types, see if their names are equivalent
476-
is_named_type(new_type)
477-
and cast(GraphQLNamedType, old_type).name
478-
== cast(GraphQLNamedType, new_type).name
479-
)
480-
elif is_list_type(old_type):
472+
if is_list_type(old_type):
481473

482474
return is_list_type(
483475
# if they're both lists, make sure underlying types are compatible
484476
new_type
485477
) and is_change_safe_for_input_object_field_or_field_arg(
486478
cast(GraphQLList, old_type).of_type, cast(GraphQLList, new_type).of_type
487479
)
488-
elif is_non_null_type(old_type):
480+
481+
if is_non_null_type(old_type):
489482
return (
490483
# if they're both non-null, make sure the underlying types are compatible
491484
is_non_null_type(new_type)
@@ -500,8 +493,13 @@ def is_change_safe_for_input_object_field_or_field_arg(
500493
cast(GraphQLNonNull, old_type).of_type, new_type
501494
)
502495
)
503-
else:
504-
return False
496+
497+
return (
498+
# if they're both named types, see if their names are equivalent
499+
is_named_type(new_type)
500+
and cast(GraphQLNamedType, old_type).name
501+
== cast(GraphQLNamedType, new_type).name
502+
)
505503

506504

507505
def find_types_removed_from_unions(

0 commit comments

Comments
 (0)