1
- from graphql .language import DirectiveLocation
2
1
from graphql .type import (
3
2
GraphQLSchema ,
4
- GraphQLDirective ,
5
3
GraphQLDeprecatedDirective ,
6
4
GraphQLIncludeDirective ,
7
5
GraphQLSkipDirective ,
13
11
find_breaking_changes ,
14
12
find_dangerous_changes ,
15
13
)
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
- )
34
14
35
15
36
16
def describe_find_breaking_changes ():
@@ -55,10 +35,10 @@ def should_detect_if_a_type_was_removed_or_not():
55
35
"""
56
36
)
57
37
58
- assert find_removed_types (old_schema , new_schema ) == [
38
+ assert find_breaking_changes (old_schema , new_schema ) == [
59
39
(BreakingChangeType .TYPE_REMOVED , "Type1 was removed." )
60
40
]
61
- assert find_removed_types (old_schema , old_schema ) == []
41
+ assert find_breaking_changes (old_schema , old_schema ) == []
62
42
63
43
def should_detect_if_a_type_changed_its_type ():
64
44
old_schema = build_schema (
@@ -79,7 +59,7 @@ def should_detect_if_a_type_changed_its_type():
79
59
"""
80
60
)
81
61
82
- assert find_types_that_changed_kind (old_schema , new_schema ) == [
62
+ assert find_breaking_changes (old_schema , new_schema ) == [
83
63
(
84
64
BreakingChangeType .TYPE_CHANGED_KIND ,
85
65
"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():
147
127
"""
148
128
)
149
129
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 ) == [
153
131
(BreakingChangeType .FIELD_REMOVED , "Type1.field2 was removed." ),
154
132
(
155
133
BreakingChangeType .FIELD_CHANGED_KIND ,
@@ -245,9 +223,7 @@ def should_detect_if_fields_on_input_types_changed_kind_or_were_removed():
245
223
"""
246
224
)
247
225
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 ) == [
251
227
(
252
228
BreakingChangeType .FIELD_CHANGED_KIND ,
253
229
"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():
311
287
"""
312
288
)
313
289
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 ) == [
317
291
(
318
292
BreakingChangeType .REQUIRED_INPUT_FIELD_ADDED ,
319
293
"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():
331
305
field1: String
332
306
}
333
307
308
+ type Type3 {
309
+ field1: String
310
+ }
311
+
334
312
union UnionType1 = Type1 | Type2
335
313
"""
336
314
)
@@ -341,6 +319,10 @@ def should_detect_if_a_type_was_removed_from_a_union_type():
341
319
field1: String
342
320
}
343
321
322
+ type Type2 {
323
+ field1: String
324
+ }
325
+
344
326
type Type3 {
345
327
field1: String
346
328
}
@@ -349,7 +331,7 @@ def should_detect_if_a_type_was_removed_from_a_union_type():
349
331
"""
350
332
)
351
333
352
- assert find_types_removed_from_unions (old_schema , new_schema ) == [
334
+ assert find_breaking_changes (old_schema , new_schema ) == [
353
335
(
354
336
BreakingChangeType .TYPE_REMOVED_FROM_UNION ,
355
337
"Type2 was removed from union type UnionType1." ,
@@ -377,7 +359,7 @@ def should_detect_if_a_value_was_removed_from_an_enum_type():
377
359
"""
378
360
)
379
361
380
- assert find_values_removed_from_enums (old_schema , new_schema ) == [
362
+ assert find_breaking_changes (old_schema , new_schema ) == [
381
363
(
382
364
BreakingChangeType .VALUE_REMOVED_FROM_ENUM ,
383
365
"VALUE1 was removed from enum type EnumType1." ,
@@ -387,12 +369,8 @@ def should_detect_if_a_value_was_removed_from_an_enum_type():
387
369
def should_detect_if_a_field_argument_was_removed ():
388
370
old_schema = build_schema (
389
371
"""
390
- input InputType1 {
391
- field1: String
392
- }
393
-
394
372
interface Interface1 {
395
- field1(arg1: Boolean, objectArg: InputType1 ): String
373
+ field1(arg1: Boolean, objectArg: String ): String
396
374
}
397
375
398
376
type Type1 {
@@ -413,7 +391,7 @@ def should_detect_if_a_field_argument_was_removed():
413
391
"""
414
392
)
415
393
416
- assert find_arg_changes (old_schema , new_schema ). breaking_changes == [
394
+ assert find_breaking_changes (old_schema , new_schema ) == [
417
395
(BreakingChangeType .ARG_REMOVED , "Interface1.field1 arg arg1 was removed" ),
418
396
(
419
397
BreakingChangeType .ARG_REMOVED ,
@@ -471,7 +449,7 @@ def should_detect_if_a_field_argument_has_changed_type():
471
449
"""
472
450
)
473
451
474
- assert find_arg_changes (old_schema , new_schema ). breaking_changes == [
452
+ assert find_breaking_changes (old_schema , new_schema ) == [
475
453
(
476
454
BreakingChangeType .ARG_CHANGED_KIND ,
477
455
"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():
544
522
"""
545
523
)
546
524
547
- assert find_arg_changes (old_schema , new_schema ). breaking_changes == [
525
+ assert find_breaking_changes (old_schema , new_schema ) == [
548
526
(
549
527
BreakingChangeType .REQUIRED_ARG_ADDED ,
550
528
"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():
576
554
"""
577
555
)
578
556
579
- assert find_arg_changes (old_schema , new_schema ). breaking_changes == []
557
+ assert find_breaking_changes (old_schema , new_schema ) == []
580
558
581
559
def should_consider_args_that_move_away_from_non_null_as_non_breaking ():
582
560
old_schema = build_schema (
@@ -595,7 +573,7 @@ def should_consider_args_that_move_away_from_non_null_as_non_breaking():
595
573
"""
596
574
)
597
575
598
- assert find_arg_changes (old_schema , new_schema ). breaking_changes == []
576
+ assert find_breaking_changes (old_schema , new_schema ) == []
599
577
600
578
def should_detect_interfaces_removed_from_types ():
601
579
old_schema = build_schema (
@@ -612,13 +590,17 @@ def should_detect_interfaces_removed_from_types():
612
590
613
591
new_schema = build_schema (
614
592
"""
593
+ interface Interface1 {
594
+ field1: String
595
+ }
596
+
615
597
type Type1 {
616
598
field1: String
617
599
}
618
600
"""
619
601
)
620
602
621
- assert find_interfaces_removed_from_object_types (old_schema , new_schema ) == [
603
+ assert find_breaking_changes (old_schema , new_schema ) == [
622
604
(
623
605
BreakingChangeType .INTERFACE_REMOVED_FROM_OBJECT ,
624
606
"Type1 no longer implements interface Interface1." ,
@@ -786,7 +768,7 @@ def should_detect_if_a_directive_was_explicitly_removed():
786
768
"""
787
769
)
788
770
789
- assert find_removed_directives (old_schema , new_schema ) == [
771
+ assert find_breaking_changes (old_schema , new_schema ) == [
790
772
(BreakingChangeType .DIRECTIVE_REMOVED , "DirectiveThatIsRemoved was removed" )
791
773
]
792
774
@@ -797,7 +779,7 @@ def should_detect_if_a_directive_was_implicitly_removed():
797
779
directives = [GraphQLSkipDirective , GraphQLIncludeDirective ]
798
780
)
799
781
800
- assert find_removed_directives (old_schema , new_schema ) == [
782
+ assert find_breaking_changes (old_schema , new_schema ) == [
801
783
(
802
784
BreakingChangeType .DIRECTIVE_REMOVED ,
803
785
f"{ GraphQLDeprecatedDirective .name } was removed" ,
@@ -807,7 +789,7 @@ def should_detect_if_a_directive_was_implicitly_removed():
807
789
def should_detect_if_a_directive_argument_was_removed ():
808
790
old_schema = build_schema (
809
791
"""
810
- directive @DirectiveWithArg(arg1: Int ) on FIELD_DEFINITION
792
+ directive @DirectiveWithArg(arg1: String ) on FIELD_DEFINITION
811
793
"""
812
794
)
813
795
@@ -817,7 +799,7 @@ def should_detect_if_a_directive_argument_was_removed():
817
799
"""
818
800
)
819
801
820
- assert find_removed_directive_args (old_schema , new_schema ) == [
802
+ assert find_breaking_changes (old_schema , new_schema ) == [
821
803
(
822
804
BreakingChangeType .DIRECTIVE_ARG_REMOVED ,
823
805
"arg1 was removed from DirectiveWithArg" ,
@@ -841,26 +823,14 @@ def should_detect_if_an_optional_directive_argument_was_added():
841
823
"""
842
824
)
843
825
844
- assert find_added_non_null_directive_args (old_schema , new_schema ) == [
826
+ assert find_breaking_changes (old_schema , new_schema ) == [
845
827
(
846
828
BreakingChangeType .REQUIRED_DIRECTIVE_ARG_ADDED ,
847
829
"A required arg newRequiredArg on directive DirectiveName was added" ,
848
830
)
849
831
]
850
832
851
833
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 ():
864
834
old_schema = build_schema (
865
835
"""
866
836
directive @DirectiveName on FIELD_DEFINITION | QUERY
@@ -873,7 +843,7 @@ def should_detect_locations_removed_directives_within_a_schema():
873
843
"""
874
844
)
875
845
876
- assert find_removed_directive_locations (old_schema , new_schema ) == [
846
+ assert find_breaking_changes (old_schema , new_schema ) == [
877
847
(
878
848
BreakingChangeType .DIRECTIVE_LOCATION_REMOVED ,
879
849
"QUERY was removed from DirectiveName" ,
@@ -882,30 +852,29 @@ def should_detect_locations_removed_directives_within_a_schema():
882
852
883
853
884
854
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
+ )
894
863
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
+ )
902
871
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
+ ]
909
878
910
879
def should_detect_if_a_value_was_added_to_an_enum_type ():
911
880
old_schema = build_schema (
@@ -927,7 +896,7 @@ def should_detect_if_a_value_was_added_to_an_enum_type():
927
896
"""
928
897
)
929
898
930
- assert find_values_added_to_enums (old_schema , new_schema ) == [
899
+ assert find_dangerous_changes (old_schema , new_schema ) == [
931
900
(
932
901
DangerousChangeType .VALUE_ADDED_TO_ENUM ,
933
902
"VALUE2 was added to enum type EnumType1." ,
@@ -955,7 +924,7 @@ def should_detect_interfaces_added_to_types():
955
924
"""
956
925
)
957
926
958
- assert find_interfaces_added_to_object_types (old_schema , new_schema ) == [
927
+ assert find_dangerous_changes (old_schema , new_schema ) == [
959
928
(
960
929
DangerousChangeType .INTERFACE_ADDED_TO_OBJECT ,
961
930
"Interface1 added to interfaces implemented by Type1." ,
@@ -987,7 +956,7 @@ def should_detect_if_a_type_was_added_to_a_union_type():
987
956
"""
988
957
)
989
958
990
- assert find_types_added_to_unions (old_schema , new_schema ) == [
959
+ assert find_dangerous_changes (old_schema , new_schema ) == [
991
960
(
992
961
DangerousChangeType .TYPE_ADDED_TO_UNION ,
993
962
"Type2 was added to union type UnionType1." ,
@@ -1012,9 +981,7 @@ def should_detect_if_an_optional_field_was_added_to_an_input():
1012
981
"""
1013
982
)
1014
983
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 ) == [
1018
985
(
1019
986
DangerousChangeType .OPTIONAL_INPUT_FIELD_ADDED ,
1020
987
"An optional field field2 on input type InputType1 was added." ,
@@ -1114,7 +1081,7 @@ def should_detect_if_an_optional_field_argument_was_added():
1114
1081
"""
1115
1082
)
1116
1083
1117
- assert find_arg_changes (old_schema , new_schema ). dangerous_changes == [
1084
+ assert find_dangerous_changes (old_schema , new_schema ) == [
1118
1085
(
1119
1086
DangerousChangeType .OPTIONAL_ARG_ADDED ,
1120
1087
"An optional arg arg2 on Type1.field1 was added" ,
0 commit comments