@@ -820,27 +820,116 @@ describe('findBreakingChanges', () => {
820
820
} ) ;
821
821
822
822
describe ( 'findDangerousChanges' , ( ) => {
823
- it ( "should detect if an argument's defaultValue has changed" , ( ) => {
824
- const oldSchema = buildSchema ( `
823
+ it ( 'should detect if a defaultValue changed on an argument' , ( ) => {
824
+ const oldSDL = `
825
+ input Input1 {
826
+ innerInputArray: [Input2]
827
+ }
828
+
829
+ input Input2 {
830
+ arrayField: [Int]
831
+ }
832
+
825
833
type Type1 {
826
- field1(name: String = "test"): String
834
+ field1(
835
+ withDefaultValue: String = "TO BE DELETED"
836
+ stringArg: String = "test"
837
+ emptyArray: [Int!] = []
838
+ valueArray: [[String]] = [["a", "b"], ["c"]]
839
+ complexObject: Input1 = {
840
+ innerInputArray: [{ arrayField: [1, 2, 3] }]
841
+ }
842
+ ): String
827
843
}
828
- ` ) ;
844
+ ` ;
845
+
846
+ const oldSchema = buildSchema ( oldSDL ) ;
847
+ const copyOfOldSchema = buildSchema ( oldSDL ) ;
848
+ expect ( findDangerousChanges ( oldSchema , copyOfOldSchema ) ) . to . deep . equal ( [ ] ) ;
829
849
830
850
const newSchema = buildSchema ( `
851
+ input Input1 {
852
+ innerInputArray: [Input2]
853
+ }
854
+
855
+ input Input2 {
856
+ arrayField: [Int]
857
+ }
858
+
831
859
type Type1 {
832
- field1(name: String = "Test"): String
860
+ field1(
861
+ withDefaultValue: String
862
+ stringArg: String = "Test"
863
+ emptyArray: [Int!] = [7]
864
+ valueArray: [[String]] = [["b", "a"], ["d"]]
865
+ complexObject: Input1 = {
866
+ innerInputArray: [{ arrayField: [3, 2, 1] }]
867
+ }
868
+ ): String
833
869
}
834
870
` ) ;
835
871
836
872
expect ( findDangerousChanges ( oldSchema , newSchema ) ) . to . deep . equal ( [
837
873
{
838
874
type : DangerousChangeType . ARG_DEFAULT_VALUE_CHANGE ,
839
- description : 'Type1.field1 arg name has changed defaultValue.' ,
875
+ description :
876
+ 'Type1.field1 arg withDefaultValue defaultValue was removed.' ,
877
+ } ,
878
+ {
879
+ type : DangerousChangeType . ARG_DEFAULT_VALUE_CHANGE ,
880
+ description :
881
+ 'Type1.field1 arg stringArg has changed defaultValue from "test" to "Test".' ,
882
+ } ,
883
+ {
884
+ type : DangerousChangeType . ARG_DEFAULT_VALUE_CHANGE ,
885
+ description :
886
+ 'Type1.field1 arg emptyArray has changed defaultValue from [] to [7].' ,
887
+ } ,
888
+ {
889
+ type : DangerousChangeType . ARG_DEFAULT_VALUE_CHANGE ,
890
+ description :
891
+ 'Type1.field1 arg valueArray has changed defaultValue from [["a", "b"], ["c"]] to [["b", "a"], ["d"]].' ,
892
+ } ,
893
+ {
894
+ type : DangerousChangeType . ARG_DEFAULT_VALUE_CHANGE ,
895
+ description :
896
+ 'Type1.field1 arg complexObject has changed defaultValue from {innerInputArray: [{arrayField: [1, 2, 3]}]} to {innerInputArray: [{arrayField: [3, 2, 1]}]}.' ,
840
897
} ,
841
898
] ) ;
842
899
} ) ;
843
900
901
+ it ( 'should ignore changes in field order of defaultValue' , ( ) => {
902
+ const oldSchema = buildSchema ( `
903
+ input Input1 {
904
+ a: String
905
+ b: String
906
+ c: String
907
+ }
908
+
909
+ type Type1 {
910
+ field1(
911
+ arg1: Input1 = { a: "a", b: "b", c: "c" }
912
+ ): String
913
+ }
914
+ ` ) ;
915
+
916
+ const newSchema = buildSchema ( `
917
+ input Input1 {
918
+ a: String
919
+ b: String
920
+ c: String
921
+ }
922
+
923
+ type Type1 {
924
+ field1(
925
+ arg1: Input1 = { c: "c", b: "b", a: "a" }
926
+ ): String
927
+ }
928
+ ` ) ;
929
+
930
+ expect ( findDangerousChanges ( oldSchema , newSchema ) ) . to . deep . equal ( [ ] ) ;
931
+ } ) ;
932
+
844
933
it ( 'should detect if a value was added to an enum type' , ( ) => {
845
934
const oldSchema = buildSchema ( `
846
935
enum EnumType1 {
@@ -979,7 +1068,7 @@ describe('findDangerousChanges', () => {
979
1068
{
980
1069
type : DangerousChangeType . ARG_DEFAULT_VALUE_CHANGE ,
981
1070
description :
982
- 'Type1.field1 arg argThatChangesDefaultValue has changed defaultValue.' ,
1071
+ 'Type1.field1 arg argThatChangesDefaultValue has changed defaultValue from "test" to "Test" .' ,
983
1072
} ,
984
1073
{
985
1074
type : DangerousChangeType . INTERFACE_ADDED_TO_OBJECT ,
0 commit comments