Skip to content

Commit e139163

Browse files
committed
find_breaking_changes: test only functions that are part of public API
Replicates graphql/graphql-js@c0cf659
1 parent e92ec01 commit e139163

File tree

1 file changed

+59
-92
lines changed

1 file changed

+59
-92
lines changed

tests/utilities/test_find_breaking_changes.py

Lines changed: 59 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
from graphql.language import DirectiveLocation
21
from graphql.type import (
32
GraphQLSchema,
4-
GraphQLDirective,
53
GraphQLDeprecatedDirective,
64
GraphQLIncludeDirective,
75
GraphQLSkipDirective,
@@ -13,24 +11,6 @@
1311
find_breaking_changes,
1412
find_dangerous_changes,
1513
)
16-
from graphql.utilities.find_breaking_changes import (
17-
find_removed_types,
18-
find_types_that_changed_kind,
19-
find_fields_that_changed_type_on_object_or_interface_types,
20-
find_fields_that_changed_type_on_input_object_types,
21-
find_types_removed_from_unions,
22-
find_values_removed_from_enums,
23-
find_arg_changes,
24-
find_interfaces_removed_from_object_types,
25-
find_removed_directives,
26-
find_removed_directive_args,
27-
find_added_non_null_directive_args,
28-
find_removed_locations_for_directive,
29-
find_removed_directive_locations,
30-
find_values_added_to_enums,
31-
find_interfaces_added_to_object_types,
32-
find_types_added_to_unions,
33-
)
3414

3515

3616
def describe_find_breaking_changes():
@@ -55,10 +35,10 @@ def should_detect_if_a_type_was_removed_or_not():
5535
"""
5636
)
5737

58-
assert find_removed_types(old_schema, new_schema) == [
38+
assert find_breaking_changes(old_schema, new_schema) == [
5939
(BreakingChangeType.TYPE_REMOVED, "Type1 was removed.")
6040
]
61-
assert find_removed_types(old_schema, old_schema) == []
41+
assert find_breaking_changes(old_schema, old_schema) == []
6242

6343
def should_detect_if_a_type_changed_its_type():
6444
old_schema = build_schema(
@@ -79,7 +59,7 @@ def should_detect_if_a_type_changed_its_type():
7959
"""
8060
)
8161

82-
assert find_types_that_changed_kind(old_schema, new_schema) == [
62+
assert find_breaking_changes(old_schema, new_schema) == [
8363
(
8464
BreakingChangeType.TYPE_CHANGED_KIND,
8565
"Type1 changed from an Interface type to a Union type.",
@@ -147,9 +127,7 @@ def should_detect_if_a_field_on_type_was_deleted_or_changed_type():
147127
"""
148128
)
149129

150-
assert find_fields_that_changed_type_on_object_or_interface_types(
151-
old_schema, new_schema
152-
) == [
130+
assert find_breaking_changes(old_schema, new_schema) == [
153131
(BreakingChangeType.FIELD_REMOVED, "Type1.field2 was removed."),
154132
(
155133
BreakingChangeType.FIELD_CHANGED_KIND,
@@ -245,9 +223,7 @@ def should_detect_if_fields_on_input_types_changed_kind_or_were_removed():
245223
"""
246224
)
247225

248-
assert find_fields_that_changed_type_on_input_object_types(
249-
old_schema, new_schema
250-
).breaking_changes == [
226+
assert find_breaking_changes(old_schema, new_schema) == [
251227
(
252228
BreakingChangeType.FIELD_CHANGED_KIND,
253229
"InputType1.field1 changed type from String to Int.",
@@ -311,9 +287,7 @@ def should_detect_if_a_required_field_is_added_to_an_input_type():
311287
"""
312288
)
313289

314-
assert find_fields_that_changed_type_on_input_object_types(
315-
old_schema, new_schema
316-
).breaking_changes == [
290+
assert find_breaking_changes(old_schema, new_schema) == [
317291
(
318292
BreakingChangeType.REQUIRED_INPUT_FIELD_ADDED,
319293
"A required field requiredField on input type InputType1 was added.",
@@ -331,6 +305,10 @@ def should_detect_if_a_type_was_removed_from_a_union_type():
331305
field1: String
332306
}
333307
308+
type Type3 {
309+
field1: String
310+
}
311+
334312
union UnionType1 = Type1 | Type2
335313
"""
336314
)
@@ -341,6 +319,10 @@ def should_detect_if_a_type_was_removed_from_a_union_type():
341319
field1: String
342320
}
343321
322+
type Type2 {
323+
field1: String
324+
}
325+
344326
type Type3 {
345327
field1: String
346328
}
@@ -349,7 +331,7 @@ def should_detect_if_a_type_was_removed_from_a_union_type():
349331
"""
350332
)
351333

352-
assert find_types_removed_from_unions(old_schema, new_schema) == [
334+
assert find_breaking_changes(old_schema, new_schema) == [
353335
(
354336
BreakingChangeType.TYPE_REMOVED_FROM_UNION,
355337
"Type2 was removed from union type UnionType1.",
@@ -377,7 +359,7 @@ def should_detect_if_a_value_was_removed_from_an_enum_type():
377359
"""
378360
)
379361

380-
assert find_values_removed_from_enums(old_schema, new_schema) == [
362+
assert find_breaking_changes(old_schema, new_schema) == [
381363
(
382364
BreakingChangeType.VALUE_REMOVED_FROM_ENUM,
383365
"VALUE1 was removed from enum type EnumType1.",
@@ -387,12 +369,8 @@ def should_detect_if_a_value_was_removed_from_an_enum_type():
387369
def should_detect_if_a_field_argument_was_removed():
388370
old_schema = build_schema(
389371
"""
390-
input InputType1 {
391-
field1: String
392-
}
393-
394372
interface Interface1 {
395-
field1(arg1: Boolean, objectArg: InputType1): String
373+
field1(arg1: Boolean, objectArg: String): String
396374
}
397375
398376
type Type1 {
@@ -413,7 +391,7 @@ def should_detect_if_a_field_argument_was_removed():
413391
"""
414392
)
415393

416-
assert find_arg_changes(old_schema, new_schema).breaking_changes == [
394+
assert find_breaking_changes(old_schema, new_schema) == [
417395
(BreakingChangeType.ARG_REMOVED, "Interface1.field1 arg arg1 was removed"),
418396
(
419397
BreakingChangeType.ARG_REMOVED,
@@ -471,7 +449,7 @@ def should_detect_if_a_field_argument_has_changed_type():
471449
"""
472450
)
473451

474-
assert find_arg_changes(old_schema, new_schema).breaking_changes == [
452+
assert find_breaking_changes(old_schema, new_schema) == [
475453
(
476454
BreakingChangeType.ARG_CHANGED_KIND,
477455
"Type1.field1 arg arg1 has changed type from String to Int",
@@ -544,7 +522,7 @@ def should_detect_if_a_required_field_argument_was_added():
544522
"""
545523
)
546524

547-
assert find_arg_changes(old_schema, new_schema).breaking_changes == [
525+
assert find_breaking_changes(old_schema, new_schema) == [
548526
(
549527
BreakingChangeType.REQUIRED_ARG_ADDED,
550528
"A required arg newRequiredArg on Type1.field1 was added",
@@ -576,7 +554,7 @@ def should_not_flag_args_with_the_same_type_signature_as_breaking():
576554
"""
577555
)
578556

579-
assert find_arg_changes(old_schema, new_schema).breaking_changes == []
557+
assert find_breaking_changes(old_schema, new_schema) == []
580558

581559
def should_consider_args_that_move_away_from_non_null_as_non_breaking():
582560
old_schema = build_schema(
@@ -595,7 +573,7 @@ def should_consider_args_that_move_away_from_non_null_as_non_breaking():
595573
"""
596574
)
597575

598-
assert find_arg_changes(old_schema, new_schema).breaking_changes == []
576+
assert find_breaking_changes(old_schema, new_schema) == []
599577

600578
def should_detect_interfaces_removed_from_types():
601579
old_schema = build_schema(
@@ -612,13 +590,17 @@ def should_detect_interfaces_removed_from_types():
612590

613591
new_schema = build_schema(
614592
"""
593+
interface Interface1 {
594+
field1: String
595+
}
596+
615597
type Type1 {
616598
field1: String
617599
}
618600
"""
619601
)
620602

621-
assert find_interfaces_removed_from_object_types(old_schema, new_schema) == [
603+
assert find_breaking_changes(old_schema, new_schema) == [
622604
(
623605
BreakingChangeType.INTERFACE_REMOVED_FROM_OBJECT,
624606
"Type1 no longer implements interface Interface1.",
@@ -786,7 +768,7 @@ def should_detect_if_a_directive_was_explicitly_removed():
786768
"""
787769
)
788770

789-
assert find_removed_directives(old_schema, new_schema) == [
771+
assert find_breaking_changes(old_schema, new_schema) == [
790772
(BreakingChangeType.DIRECTIVE_REMOVED, "DirectiveThatIsRemoved was removed")
791773
]
792774

@@ -797,7 +779,7 @@ def should_detect_if_a_directive_was_implicitly_removed():
797779
directives=[GraphQLSkipDirective, GraphQLIncludeDirective]
798780
)
799781

800-
assert find_removed_directives(old_schema, new_schema) == [
782+
assert find_breaking_changes(old_schema, new_schema) == [
801783
(
802784
BreakingChangeType.DIRECTIVE_REMOVED,
803785
f"{GraphQLDeprecatedDirective.name} was removed",
@@ -807,7 +789,7 @@ def should_detect_if_a_directive_was_implicitly_removed():
807789
def should_detect_if_a_directive_argument_was_removed():
808790
old_schema = build_schema(
809791
"""
810-
directive @DirectiveWithArg(arg1: Int) on FIELD_DEFINITION
792+
directive @DirectiveWithArg(arg1: String) on FIELD_DEFINITION
811793
"""
812794
)
813795

@@ -817,7 +799,7 @@ def should_detect_if_a_directive_argument_was_removed():
817799
"""
818800
)
819801

820-
assert find_removed_directive_args(old_schema, new_schema) == [
802+
assert find_breaking_changes(old_schema, new_schema) == [
821803
(
822804
BreakingChangeType.DIRECTIVE_ARG_REMOVED,
823805
"arg1 was removed from DirectiveWithArg",
@@ -841,26 +823,14 @@ def should_detect_if_an_optional_directive_argument_was_added():
841823
"""
842824
)
843825

844-
assert find_added_non_null_directive_args(old_schema, new_schema) == [
826+
assert find_breaking_changes(old_schema, new_schema) == [
845827
(
846828
BreakingChangeType.REQUIRED_DIRECTIVE_ARG_ADDED,
847829
"A required arg newRequiredArg on directive DirectiveName was added",
848830
)
849831
]
850832

851833
def should_detect_locations_removed_from_a_directive():
852-
d1 = GraphQLDirective(
853-
"Directive Name",
854-
locations=[DirectiveLocation.FIELD_DEFINITION, DirectiveLocation.QUERY],
855-
)
856-
857-
d2 = GraphQLDirective(
858-
"Directive Name", locations=[DirectiveLocation.FIELD_DEFINITION]
859-
)
860-
861-
assert find_removed_locations_for_directive(d1, d2) == [DirectiveLocation.QUERY]
862-
863-
def should_detect_locations_removed_directives_within_a_schema():
864834
old_schema = build_schema(
865835
"""
866836
directive @DirectiveName on FIELD_DEFINITION | QUERY
@@ -873,7 +843,7 @@ def should_detect_locations_removed_directives_within_a_schema():
873843
"""
874844
)
875845

876-
assert find_removed_directive_locations(old_schema, new_schema) == [
846+
assert find_breaking_changes(old_schema, new_schema) == [
877847
(
878848
BreakingChangeType.DIRECTIVE_LOCATION_REMOVED,
879849
"QUERY was removed from DirectiveName",
@@ -882,30 +852,29 @@ def should_detect_locations_removed_directives_within_a_schema():
882852

883853

884854
def describe_find_dangerous_changes():
885-
def describe_find_arg_changes():
886-
def should_detect_if_an_arguments_default_value_has_changed():
887-
old_schema = build_schema(
888-
"""
889-
type Type1 {
890-
field1(name: String = "test"): String
891-
}
892-
"""
893-
)
855+
def should_detect_if_an_arguments_default_value_has_changed():
856+
old_schema = build_schema(
857+
"""
858+
type Type1 {
859+
field1(name: String = "test"): String
860+
}
861+
"""
862+
)
894863

895-
new_schema = build_schema(
896-
"""
897-
type Type1 {
898-
field1(name: String = "Test"): String
899-
}
900-
"""
901-
)
864+
new_schema = build_schema(
865+
"""
866+
type Type1 {
867+
field1(name: String = "Test"): String
868+
}
869+
"""
870+
)
902871

903-
assert find_arg_changes(old_schema, new_schema).dangerous_changes == [
904-
(
905-
DangerousChangeType.ARG_DEFAULT_VALUE_CHANGE,
906-
"Type1.field1 arg name has changed defaultValue",
907-
)
908-
]
872+
assert find_dangerous_changes(old_schema, new_schema) == [
873+
(
874+
DangerousChangeType.ARG_DEFAULT_VALUE_CHANGE,
875+
"Type1.field1 arg name has changed defaultValue",
876+
)
877+
]
909878

910879
def should_detect_if_a_value_was_added_to_an_enum_type():
911880
old_schema = build_schema(
@@ -927,7 +896,7 @@ def should_detect_if_a_value_was_added_to_an_enum_type():
927896
"""
928897
)
929898

930-
assert find_values_added_to_enums(old_schema, new_schema) == [
899+
assert find_dangerous_changes(old_schema, new_schema) == [
931900
(
932901
DangerousChangeType.VALUE_ADDED_TO_ENUM,
933902
"VALUE2 was added to enum type EnumType1.",
@@ -955,7 +924,7 @@ def should_detect_interfaces_added_to_types():
955924
"""
956925
)
957926

958-
assert find_interfaces_added_to_object_types(old_schema, new_schema) == [
927+
assert find_dangerous_changes(old_schema, new_schema) == [
959928
(
960929
DangerousChangeType.INTERFACE_ADDED_TO_OBJECT,
961930
"Interface1 added to interfaces implemented by Type1.",
@@ -987,7 +956,7 @@ def should_detect_if_a_type_was_added_to_a_union_type():
987956
"""
988957
)
989958

990-
assert find_types_added_to_unions(old_schema, new_schema) == [
959+
assert find_dangerous_changes(old_schema, new_schema) == [
991960
(
992961
DangerousChangeType.TYPE_ADDED_TO_UNION,
993962
"Type2 was added to union type UnionType1.",
@@ -1012,9 +981,7 @@ def should_detect_if_an_optional_field_was_added_to_an_input():
1012981
"""
1013982
)
1014983

1015-
assert find_fields_that_changed_type_on_input_object_types(
1016-
old_schema, new_schema
1017-
).dangerous_changes == [
984+
assert find_dangerous_changes(old_schema, new_schema) == [
1018985
(
1019986
DangerousChangeType.OPTIONAL_INPUT_FIELD_ADDED,
1020987
"An optional field field2 on input type InputType1 was added.",
@@ -1114,7 +1081,7 @@ def should_detect_if_an_optional_field_argument_was_added():
11141081
"""
11151082
)
11161083

1117-
assert find_arg_changes(old_schema, new_schema).dangerous_changes == [
1084+
assert find_dangerous_changes(old_schema, new_schema) == [
11181085
(
11191086
DangerousChangeType.OPTIONAL_ARG_ADDED,
11201087
"An optional arg arg2 on Type1.field1 was added",

0 commit comments

Comments
 (0)