Skip to content

Commit f8f4bed

Browse files
committed
find_breaking_changes: Remove unnecessary fields
Replicates graphql/graphql-js@ec020fb
1 parent 6d6e89e commit f8f4bed

File tree

1 file changed

+48
-142
lines changed

1 file changed

+48
-142
lines changed

tests/utilities/test_find_breaking_changes.py

Lines changed: 48 additions & 142 deletions
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,14 @@ def describe_find_breaking_changes():
1717
def should_detect_if_a_type_was_removed_or_not():
1818
old_schema = build_schema(
1919
"""
20-
type Type1 {
21-
field1: String
22-
}
23-
24-
type Type2 {
25-
field1: String
26-
}
20+
type Type1
21+
type Type2
2722
"""
2823
)
2924

3025
new_schema = build_schema(
3126
"""
32-
type Type2 {
33-
field1: String
34-
}
27+
type Type2
3528
"""
3629
)
3730

@@ -43,19 +36,13 @@ def should_detect_if_a_type_was_removed_or_not():
4336
def should_detect_if_a_type_changed_its_type():
4437
old_schema = build_schema(
4538
"""
46-
interface Type1 {
47-
field1: String
48-
}
39+
interface Type1
4940
"""
5041
)
5142

5243
new_schema = build_schema(
5344
"""
54-
type ObjectType {
55-
field1: String
56-
}
57-
58-
union Type1 = ObjectType
45+
union Type1
5946
"""
6047
)
6148

@@ -69,9 +56,8 @@ def should_detect_if_a_type_changed_its_type():
6956
def should_detect_if_a_field_on_type_was_deleted_or_changed_type():
7057
old_schema = build_schema(
7158
"""
72-
type TypeA {
73-
field1: String
74-
}
59+
type TypeA
60+
type TypeB
7561
7662
interface Type1 {
7763
field1: TypeA
@@ -97,13 +83,8 @@ def should_detect_if_a_field_on_type_was_deleted_or_changed_type():
9783

9884
new_schema = build_schema(
9985
"""
100-
type TypeA {
101-
field1: String
102-
}
103-
104-
type TypeB {
105-
field1: String
106-
}
86+
type TypeA
87+
type TypeB
10788
10889
interface Type1 {
10990
field1: TypeA
@@ -297,35 +278,19 @@ def should_detect_if_a_required_field_is_added_to_an_input_type():
297278
def should_detect_if_a_type_was_removed_from_a_union_type():
298279
old_schema = build_schema(
299280
"""
300-
type Type1 {
301-
field1: String
302-
}
303-
304-
type Type2 {
305-
field1: String
306-
}
307-
308-
type Type3 {
309-
field1: String
310-
}
281+
type Type1
282+
type Type2
283+
type Type3
311284
312285
union UnionType1 = Type1 | Type2
313286
"""
314287
)
315288

316289
new_schema = build_schema(
317290
"""
318-
type Type1 {
319-
field1: String
320-
}
321-
322-
type Type2 {
323-
field1: String
324-
}
325-
326-
type Type3 {
327-
field1: String
328-
}
291+
type Type1
292+
type Type2
293+
type Type3
329294
330295
union UnionType1 = Type1 | Type3
331296
"""
@@ -578,25 +543,17 @@ def should_consider_args_that_move_away_from_non_null_as_non_breaking():
578543
def should_detect_interfaces_removed_from_types():
579544
old_schema = build_schema(
580545
"""
581-
interface Interface1 {
582-
field1: String
583-
}
546+
interface Interface1
584547
585-
type Type1 implements Interface1 {
586-
field1: String
587-
}
548+
type Type1 implements Interface1
588549
"""
589550
)
590551

591552
new_schema = build_schema(
592553
"""
593-
interface Interface1 {
594-
field1: String
595-
}
554+
interface Interface1
596555
597-
type Type1 {
598-
field1: String
599-
}
556+
type Type1
600557
"""
601558
)
602559

@@ -628,31 +585,16 @@ def should_detect_all_breaking_changes():
628585
VALUE2
629586
}
630587
631-
interface Interface1 {
632-
field1: String
633-
}
634-
635-
type TypeThatGainsInterface1 implements Interface1 {
636-
field1: String
637-
}
638-
639-
type TypeInUnion1 {
640-
field1: String
641-
}
642-
643-
type TypeInUnion2 {
644-
field1: String
645-
}
588+
interface Interface1
589+
type TypeThatLoosesInterface1 implements Interface1
646590
591+
type TypeInUnion1
592+
type TypeInUnion2
647593
union UnionTypeThatLosesAType = TypeInUnion1 | TypeInUnion2
648594
649-
type TypeThatChangesType {
650-
field1: String
651-
}
595+
type TypeThatChangesType
652596
653-
type TypeThatGetsRemoved {
654-
field1: String
655-
}
597+
type TypeThatGetsRemoved
656598
657599
interface TypeThatHasBreakingFieldChanges {
658600
field1: String
@@ -678,23 +620,15 @@ def should_detect_all_breaking_changes():
678620
VALUE2
679621
}
680622
681-
interface Interface1 {
682-
field1: String
683-
}
623+
interface Interface1
624+
type TypeThatLoosesInterface1
684625
685-
type TypeInUnion1 {
686-
field1: String
687-
}
626+
type TypeInUnion1
627+
type TypeInUnion2
688628
689629
union UnionTypeThatLosesAType = TypeInUnion1
690630
691-
interface TypeThatChangesType {
692-
field1: String
693-
}
694-
695-
type TypeThatGainsInterface1 {
696-
field1: String
697-
}
631+
interface TypeThatChangesType
698632
699633
interface TypeThatHasBreakingFieldChanges {
700634
field2: Boolean
@@ -704,7 +638,6 @@ def should_detect_all_breaking_changes():
704638

705639
assert find_breaking_changes(old_schema, new_schema) == [
706640
(BreakingChangeType.TYPE_REMOVED, "Int was removed."),
707-
(BreakingChangeType.TYPE_REMOVED, "TypeInUnion2 was removed."),
708641
(BreakingChangeType.TYPE_REMOVED, "TypeThatGetsRemoved was removed."),
709642
(
710643
BreakingChangeType.TYPE_CHANGED_KIND,
@@ -734,7 +667,7 @@ def should_detect_all_breaking_changes():
734667
),
735668
(
736669
BreakingChangeType.INTERFACE_REMOVED_FROM_OBJECT,
737-
"TypeThatGainsInterface1 no longer implements interface Interface1.",
670+
"TypeThatLoosesInterface1 no longer implements interface Interface1.",
738671
),
739672
(
740673
BreakingChangeType.DIRECTIVE_REMOVED,
@@ -906,21 +839,15 @@ def should_detect_if_a_value_was_added_to_an_enum_type():
906839
def should_detect_interfaces_added_to_types():
907840
old_schema = build_schema(
908841
"""
909-
type Type1 {
910-
field1: String
911-
}
842+
type Type1
912843
"""
913844
)
914845

915846
new_schema = build_schema(
916847
"""
917-
interface Interface1 {
918-
field1: String
919-
}
848+
interface Interface1
920849
921-
type Type1 implements Interface1 {
922-
field1: String
923-
}
850+
type Type1 implements Interface1
924851
"""
925852
)
926853

@@ -934,23 +861,17 @@ def should_detect_interfaces_added_to_types():
934861
def should_detect_if_a_type_was_added_to_a_union_type():
935862
old_schema = build_schema(
936863
"""
937-
type Type1 {
938-
field1: String
939-
}
864+
type Type1
865+
type Type2
940866
941867
union UnionType1 = Type1
942868
"""
943869
)
944870

945871
new_schema = build_schema(
946872
"""
947-
type Type1 {
948-
field1: String
949-
}
950-
951-
type Type2 {
952-
field1: String
953-
}
873+
type Type1
874+
type Type2
954875
955876
union UnionType1 = Type1 | Type2
956877
"""
@@ -997,17 +918,13 @@ def should_find_all_dangerous_changes():
997918
}
998919
999920
type Type1 {
1000-
field1(name: String = "test"): String
921+
field1(argThatChangesDefaultValue: String = "test"): String
1001922
}
1002923
1003-
type TypeThatGainsInterface1 {
1004-
field1: String
1005-
}
1006-
1007-
type TypeInUnion1 {
1008-
field1: String
1009-
}
924+
interface Interface1
925+
type TypeThatGainsInterface1
1010926
927+
type TypeInUnion1
1011928
union UnionTypeThatGainsAType = TypeInUnion1
1012929
"""
1013930
)
@@ -1020,34 +937,23 @@ def should_find_all_dangerous_changes():
1020937
VALUE2
1021938
}
1022939
1023-
interface Interface1 {
1024-
field1: String
1025-
}
1026-
1027-
type TypeThatGainsInterface1 implements Interface1 {
1028-
field1: String
1029-
}
1030-
1031940
type Type1 {
1032-
field1(name: String = "Test"): String
941+
field1(argThatChangesDefaultValue: String = "Test"): String
1033942
}
1034943
1035-
type TypeInUnion1 {
1036-
field1: String
1037-
}
1038-
1039-
type TypeInUnion2 {
1040-
field1: String
1041-
}
944+
interface Interface1
945+
type TypeThatGainsInterface1 implements Interface1
1042946
947+
type TypeInUnion1
948+
type TypeInUnion2
1043949
union UnionTypeThatGainsAType = TypeInUnion1 | TypeInUnion2
1044950
"""
1045951
)
1046952

1047953
assert find_dangerous_changes(old_schema, new_schema) == [
1048954
(
1049955
DangerousChangeType.ARG_DEFAULT_VALUE_CHANGE,
1050-
"Type1.field1 arg name has changed defaultValue",
956+
"Type1.field1 arg argThatChangesDefaultValue has changed defaultValue",
1051957
),
1052958
(
1053959
DangerousChangeType.VALUE_ADDED_TO_ENUM,

0 commit comments

Comments
 (0)