@@ -14,11 +14,10 @@ import { buildSchema } from '../buildASTSchema';
14
14
import {
15
15
BreakingChangeType ,
16
16
DangerousChangeType ,
17
- findBreakingChanges ,
18
- findDangerousChanges ,
17
+ findSchemaChanges ,
19
18
} from '../findBreakingChanges' ;
20
19
21
- describe ( 'findBreakingChanges ' , ( ) => {
20
+ describe ( 'findSchemaChanges ' , ( ) => {
22
21
it ( 'should detect if a type was removed or not' , ( ) => {
23
22
const oldSchema = buildSchema ( `
24
23
type Type1
@@ -28,13 +27,13 @@ describe('findBreakingChanges', () => {
28
27
const newSchema = buildSchema ( `
29
28
type Type2
30
29
` ) ;
31
- expect ( findBreakingChanges ( oldSchema , newSchema ) ) . to . deep . equal ( [
30
+ expect ( findSchemaChanges ( oldSchema , newSchema ) ) . to . deep . equal ( [
32
31
{
33
32
type : BreakingChangeType . TYPE_REMOVED ,
34
33
description : 'Type1 was removed.' ,
35
34
} ,
36
35
] ) ;
37
- expect ( findBreakingChanges ( oldSchema , oldSchema ) ) . to . deep . equal ( [ ] ) ;
36
+ expect ( findSchemaChanges ( oldSchema , oldSchema ) ) . to . deep . equal ( [ ] ) ;
38
37
} ) ;
39
38
40
39
it ( 'should detect if a type changed its type' , ( ) => {
@@ -49,7 +48,7 @@ describe('findBreakingChanges', () => {
49
48
union TypeWasInterfaceBecomesUnion
50
49
input TypeWasObjectBecomesInputObject
51
50
` ) ;
52
- expect ( findBreakingChanges ( oldSchema , newSchema ) ) . to . deep . equal ( [
51
+ expect ( findSchemaChanges ( oldSchema , newSchema ) ) . to . deep . equal ( [
53
52
{
54
53
type : BreakingChangeType . TYPE_CHANGED_KIND ,
55
54
description :
@@ -119,7 +118,7 @@ describe('findBreakingChanges', () => {
119
118
}
120
119
` ) ;
121
120
122
- const changes = findBreakingChanges ( oldSchema , newSchema ) ;
121
+ const changes = findSchemaChanges ( oldSchema , newSchema ) ;
123
122
expect ( changes ) . to . deep . equal ( [
124
123
{
125
124
type : BreakingChangeType . FIELD_REMOVED ,
@@ -216,7 +215,7 @@ describe('findBreakingChanges', () => {
216
215
}
217
216
` ) ;
218
217
219
- expect ( findBreakingChanges ( oldSchema , newSchema ) ) . to . deep . equal ( [
218
+ expect ( findSchemaChanges ( oldSchema , newSchema ) ) . to . deep . equal ( [
220
219
{
221
220
type : BreakingChangeType . FIELD_REMOVED ,
222
221
description : 'InputType1.field2 was removed.' ,
@@ -281,12 +280,22 @@ describe('findBreakingChanges', () => {
281
280
}
282
281
` ) ;
283
282
284
- expect ( findBreakingChanges ( oldSchema , newSchema ) ) . to . deep . equal ( [
283
+ expect ( findSchemaChanges ( oldSchema , newSchema ) ) . to . deep . equal ( [
285
284
{
286
285
type : BreakingChangeType . REQUIRED_INPUT_FIELD_ADDED ,
287
286
description :
288
287
'A required field requiredField on input type InputType1 was added.' ,
289
288
} ,
289
+ {
290
+ description :
291
+ 'An optional field optionalField1 on input type InputType1 was added.' ,
292
+ type : 'OPTIONAL_INPUT_FIELD_ADDED' ,
293
+ } ,
294
+ {
295
+ description :
296
+ 'An optional field optionalField2 on input type InputType1 was added.' ,
297
+ type : 'OPTIONAL_INPUT_FIELD_ADDED' ,
298
+ } ,
290
299
] ) ;
291
300
} ) ;
292
301
@@ -306,7 +315,11 @@ describe('findBreakingChanges', () => {
306
315
union UnionType1 = Type1 | Type3
307
316
` ) ;
308
317
309
- expect ( findBreakingChanges ( oldSchema , newSchema ) ) . to . deep . equal ( [
318
+ expect ( findSchemaChanges ( oldSchema , newSchema ) ) . to . deep . equal ( [
319
+ {
320
+ description : 'Type3 was added to union type UnionType1.' ,
321
+ type : 'TYPE_ADDED_TO_UNION' ,
322
+ } ,
310
323
{
311
324
type : BreakingChangeType . TYPE_REMOVED_FROM_UNION ,
312
325
description : 'Type2 was removed from union type UnionType1.' ,
@@ -331,7 +344,11 @@ describe('findBreakingChanges', () => {
331
344
}
332
345
` ) ;
333
346
334
- expect ( findBreakingChanges ( oldSchema , newSchema ) ) . to . deep . equal ( [
347
+ expect ( findSchemaChanges ( oldSchema , newSchema ) ) . to . deep . equal ( [
348
+ {
349
+ description : 'VALUE3 was added to enum type EnumType1.' ,
350
+ type : 'VALUE_ADDED_TO_ENUM' ,
351
+ } ,
335
352
{
336
353
type : BreakingChangeType . VALUE_REMOVED_FROM_ENUM ,
337
354
description : 'VALUE1 was removed from enum type EnumType1.' ,
@@ -360,7 +377,7 @@ describe('findBreakingChanges', () => {
360
377
}
361
378
` ) ;
362
379
363
- expect ( findBreakingChanges ( oldSchema , newSchema ) ) . to . deep . equal ( [
380
+ expect ( findSchemaChanges ( oldSchema , newSchema ) ) . to . deep . equal ( [
364
381
{
365
382
type : BreakingChangeType . ARG_REMOVED ,
366
383
description : 'Interface1.field1 arg arg1 was removed.' ,
@@ -421,7 +438,7 @@ describe('findBreakingChanges', () => {
421
438
}
422
439
` ) ;
423
440
424
- expect ( findBreakingChanges ( oldSchema , newSchema ) ) . to . deep . equal ( [
441
+ expect ( findSchemaChanges ( oldSchema , newSchema ) ) . to . deep . equal ( [
425
442
{
426
443
type : BreakingChangeType . ARG_CHANGED_KIND ,
427
444
description :
@@ -503,11 +520,21 @@ describe('findBreakingChanges', () => {
503
520
}
504
521
` ) ;
505
522
506
- expect ( findBreakingChanges ( oldSchema , newSchema ) ) . to . deep . equal ( [
523
+ expect ( findSchemaChanges ( oldSchema , newSchema ) ) . to . deep . equal ( [
507
524
{
508
525
type : BreakingChangeType . REQUIRED_ARG_ADDED ,
509
526
description : 'A required arg newRequiredArg on Type1.field1 was added.' ,
510
527
} ,
528
+ {
529
+ description :
530
+ 'An optional arg newOptionalArg1 on Type1.field1 was added.' ,
531
+ type : 'OPTIONAL_ARG_ADDED' ,
532
+ } ,
533
+ {
534
+ description :
535
+ 'An optional arg newOptionalArg2 on Type1.field1 was added.' ,
536
+ type : 'OPTIONAL_ARG_ADDED' ,
537
+ } ,
511
538
] ) ;
512
539
} ) ;
513
540
@@ -532,7 +559,7 @@ describe('findBreakingChanges', () => {
532
559
}
533
560
` ) ;
534
561
535
- expect ( findBreakingChanges ( oldSchema , newSchema ) ) . to . deep . equal ( [ ] ) ;
562
+ expect ( findSchemaChanges ( oldSchema , newSchema ) ) . to . deep . equal ( [ ] ) ;
536
563
} ) ;
537
564
538
565
it ( 'should consider args that move away from NonNull as non-breaking' , ( ) => {
@@ -548,7 +575,7 @@ describe('findBreakingChanges', () => {
548
575
}
549
576
` ) ;
550
577
551
- expect ( findBreakingChanges ( oldSchema , newSchema ) ) . to . deep . equal ( [ ] ) ;
578
+ expect ( findSchemaChanges ( oldSchema , newSchema ) ) . to . deep . equal ( [ ] ) ;
552
579
} ) ;
553
580
554
581
it ( 'should detect interfaces removed from types' , ( ) => {
@@ -564,7 +591,7 @@ describe('findBreakingChanges', () => {
564
591
type Type1
565
592
` ) ;
566
593
567
- expect ( findBreakingChanges ( oldSchema , newSchema ) ) . to . deep . equal ( [
594
+ expect ( findSchemaChanges ( oldSchema , newSchema ) ) . to . deep . equal ( [
568
595
{
569
596
type : BreakingChangeType . INTERFACE_REMOVED_FROM_OBJECT ,
570
597
description : 'Type1 no longer implements interface Interface1.' ,
@@ -587,7 +614,7 @@ describe('findBreakingChanges', () => {
587
614
type Type1 implements SecondInterface & FirstInterface
588
615
` ) ;
589
616
590
- expect ( findBreakingChanges ( oldSchema , newSchema ) ) . to . deep . equal ( [ ] ) ;
617
+ expect ( findSchemaChanges ( oldSchema , newSchema ) ) . to . deep . equal ( [ ] ) ;
591
618
} ) ;
592
619
593
620
it ( 'should detect all breaking changes' , ( ) => {
@@ -657,7 +684,7 @@ describe('findBreakingChanges', () => {
657
684
}
658
685
` ) ;
659
686
660
- expect ( findBreakingChanges ( oldSchema , newSchema ) ) . to . deep . equal ( [
687
+ expect ( findSchemaChanges ( oldSchema , newSchema ) ) . to . deep . equal ( [
661
688
{
662
689
type : BreakingChangeType . TYPE_REMOVED ,
663
690
description : 'Int was removed.' ,
@@ -730,7 +757,7 @@ describe('findBreakingChanges', () => {
730
757
directive @DirectiveThatStays on FIELD_DEFINITION
731
758
` ) ;
732
759
733
- expect ( findBreakingChanges ( oldSchema , newSchema ) ) . to . deep . equal ( [
760
+ expect ( findSchemaChanges ( oldSchema , newSchema ) ) . to . deep . equal ( [
734
761
{
735
762
type : BreakingChangeType . DIRECTIVE_REMOVED ,
736
763
description : 'DirectiveThatIsRemoved was removed.' ,
@@ -745,7 +772,7 @@ describe('findBreakingChanges', () => {
745
772
directives : [ GraphQLSkipDirective , GraphQLIncludeDirective ] ,
746
773
} ) ;
747
774
748
- expect ( findBreakingChanges ( oldSchema , newSchema ) ) . to . deep . equal ( [
775
+ expect ( findSchemaChanges ( oldSchema , newSchema ) ) . to . deep . equal ( [
749
776
{
750
777
type : BreakingChangeType . DIRECTIVE_REMOVED ,
751
778
description : `${ GraphQLDeprecatedDirective . name } was removed.` ,
@@ -762,7 +789,7 @@ describe('findBreakingChanges', () => {
762
789
directive @DirectiveWithArg on FIELD_DEFINITION
763
790
` ) ;
764
791
765
- expect ( findBreakingChanges ( oldSchema , newSchema ) ) . to . deep . equal ( [
792
+ expect ( findSchemaChanges ( oldSchema , newSchema ) ) . to . deep . equal ( [
766
793
{
767
794
type : BreakingChangeType . DIRECTIVE_ARG_REMOVED ,
768
795
description : 'arg1 was removed from DirectiveWithArg.' ,
@@ -783,7 +810,7 @@ describe('findBreakingChanges', () => {
783
810
) on FIELD_DEFINITION
784
811
` ) ;
785
812
786
- expect ( findBreakingChanges ( oldSchema , newSchema ) ) . to . deep . equal ( [
813
+ expect ( findSchemaChanges ( oldSchema , newSchema ) ) . to . deep . equal ( [
787
814
{
788
815
type : BreakingChangeType . REQUIRED_DIRECTIVE_ARG_ADDED ,
789
816
description :
@@ -801,7 +828,7 @@ describe('findBreakingChanges', () => {
801
828
directive @DirectiveName on FIELD_DEFINITION
802
829
` ) ;
803
830
804
- expect ( findBreakingChanges ( oldSchema , newSchema ) ) . to . deep . equal ( [
831
+ expect ( findSchemaChanges ( oldSchema , newSchema ) ) . to . deep . equal ( [
805
832
{
806
833
type : BreakingChangeType . DIRECTIVE_LOCATION_REMOVED ,
807
834
description : 'QUERY was removed from DirectiveName.' ,
@@ -810,7 +837,7 @@ describe('findBreakingChanges', () => {
810
837
} ) ;
811
838
} ) ;
812
839
813
- describe ( 'findDangerousChanges ' , ( ) => {
840
+ describe ( 'findSchemaChanges ' , ( ) => {
814
841
it ( 'should detect if a defaultValue changed on an argument' , ( ) => {
815
842
const oldSDL = `
816
843
input Input1 {
@@ -836,7 +863,7 @@ describe('findDangerousChanges', () => {
836
863
837
864
const oldSchema = buildSchema ( oldSDL ) ;
838
865
const copyOfOldSchema = buildSchema ( oldSDL ) ;
839
- expect ( findDangerousChanges ( oldSchema , copyOfOldSchema ) ) . to . deep . equal ( [ ] ) ;
866
+ expect ( findSchemaChanges ( oldSchema , copyOfOldSchema ) ) . to . deep . equal ( [ ] ) ;
840
867
841
868
const newSchema = buildSchema ( `
842
869
input Input1 {
@@ -860,7 +887,7 @@ describe('findDangerousChanges', () => {
860
887
}
861
888
` ) ;
862
889
863
- expect ( findDangerousChanges ( oldSchema , newSchema ) ) . to . deep . equal ( [
890
+ expect ( findSchemaChanges ( oldSchema , newSchema ) ) . to . deep . equal ( [
864
891
{
865
892
type : DangerousChangeType . ARG_DEFAULT_VALUE_CHANGE ,
866
893
description :
@@ -918,7 +945,7 @@ describe('findDangerousChanges', () => {
918
945
}
919
946
` ) ;
920
947
921
- expect ( findDangerousChanges ( oldSchema , newSchema ) ) . to . deep . equal ( [ ] ) ;
948
+ expect ( findSchemaChanges ( oldSchema , newSchema ) ) . to . deep . equal ( [ ] ) ;
922
949
} ) ;
923
950
924
951
it ( 'should ignore changes in field definitions order' , ( ) => {
@@ -950,7 +977,7 @@ describe('findDangerousChanges', () => {
950
977
}
951
978
` ) ;
952
979
953
- expect ( findDangerousChanges ( oldSchema , newSchema ) ) . to . deep . equal ( [ ] ) ;
980
+ expect ( findSchemaChanges ( oldSchema , newSchema ) ) . to . deep . equal ( [ ] ) ;
954
981
} ) ;
955
982
956
983
it ( 'should detect if a value was added to an enum type' , ( ) => {
@@ -969,7 +996,7 @@ describe('findDangerousChanges', () => {
969
996
}
970
997
` ) ;
971
998
972
- expect ( findDangerousChanges ( oldSchema , newSchema ) ) . to . deep . equal ( [
999
+ expect ( findSchemaChanges ( oldSchema , newSchema ) ) . to . deep . equal ( [
973
1000
{
974
1001
type : DangerousChangeType . VALUE_ADDED_TO_ENUM ,
975
1002
description : 'VALUE2 was added to enum type EnumType1.' ,
@@ -992,7 +1019,7 @@ describe('findDangerousChanges', () => {
992
1019
type Type1 implements OldInterface & NewInterface
993
1020
` ) ;
994
1021
995
- expect ( findDangerousChanges ( oldSchema , newSchema ) ) . to . deep . equal ( [
1022
+ expect ( findSchemaChanges ( oldSchema , newSchema ) ) . to . deep . equal ( [
996
1023
{
997
1024
type : DangerousChangeType . INTERFACE_ADDED_TO_OBJECT ,
998
1025
description : 'NewInterface added to interfaces implemented by Type1.' ,
@@ -1015,7 +1042,7 @@ describe('findDangerousChanges', () => {
1015
1042
union UnionType1 = Type1 | Type2
1016
1043
` ) ;
1017
1044
1018
- expect ( findDangerousChanges ( oldSchema , newSchema ) ) . to . deep . equal ( [
1045
+ expect ( findSchemaChanges ( oldSchema , newSchema ) ) . to . deep . equal ( [
1019
1046
{
1020
1047
type : DangerousChangeType . TYPE_ADDED_TO_UNION ,
1021
1048
description : 'Type2 was added to union type UnionType1.' ,
@@ -1037,7 +1064,7 @@ describe('findDangerousChanges', () => {
1037
1064
}
1038
1065
` ) ;
1039
1066
1040
- expect ( findDangerousChanges ( oldSchema , newSchema ) ) . to . deep . equal ( [
1067
+ expect ( findSchemaChanges ( oldSchema , newSchema ) ) . to . deep . equal ( [
1041
1068
{
1042
1069
type : DangerousChangeType . OPTIONAL_INPUT_FIELD_ADDED ,
1043
1070
description :
@@ -1083,7 +1110,7 @@ describe('findDangerousChanges', () => {
1083
1110
union UnionTypeThatGainsAType = TypeInUnion1 | TypeInUnion2
1084
1111
` ) ;
1085
1112
1086
- expect ( findDangerousChanges ( oldSchema , newSchema ) ) . to . deep . equal ( [
1113
+ expect ( findSchemaChanges ( oldSchema , newSchema ) ) . to . deep . equal ( [
1087
1114
{
1088
1115
type : DangerousChangeType . VALUE_ADDED_TO_ENUM ,
1089
1116
description : 'VALUE2 was added to enum type EnumType1.' ,
@@ -1119,7 +1146,7 @@ describe('findDangerousChanges', () => {
1119
1146
}
1120
1147
` ) ;
1121
1148
1122
- expect ( findDangerousChanges ( oldSchema , newSchema ) ) . to . deep . equal ( [
1149
+ expect ( findSchemaChanges ( oldSchema , newSchema ) ) . to . deep . equal ( [
1123
1150
{
1124
1151
type : DangerousChangeType . OPTIONAL_ARG_ADDED ,
1125
1152
description : 'An optional arg arg2 on Type1.field1 was added.' ,
0 commit comments