You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -254,26 +254,92 @@ describe('Validate: Overlapping fields can be merged', () => {
254
254
`);
255
255
});
256
256
257
-
it('disallows different nullability status even if the types are mutual exclusive',()=>{
258
-
expectErrors(`
259
-
fragment conflictingNullability on Pet {
260
-
... on Dog {
261
-
name!
257
+
describe('disallows different nullability status even if the types are mutually exclusive',()=>{
258
+
it('for required and unset',()=>{
259
+
expectErrors(`
260
+
fragment conflictingNullability on Pet {
261
+
... on Dog {
262
+
name!
263
+
}
264
+
... on Cat {
265
+
name
266
+
}
262
267
}
263
-
... on Cat {
264
-
name
268
+
`).to.deep.equal([
269
+
{
270
+
message:
271
+
'Fields "name" conflict because they return conflicting types "String!" and "String". Use different aliases on the fields to fetch both if this was intentional.',
272
+
locations: [
273
+
{line: 4,column: 13},
274
+
{line: 7,column: 13},
275
+
],
276
+
},
277
+
]);
278
+
});
279
+
280
+
it('for required and optional',()=>{
281
+
expectErrors(`
282
+
fragment conflictingNullability on Pet {
283
+
... on Dog {
284
+
name!
285
+
}
286
+
... on Cat {
287
+
name?
288
+
}
265
289
}
266
-
}
267
-
`).to.deep.equal([
268
-
{
269
-
message:
270
-
'Fields "name" conflict because they return conflicting types "String!" and "String". Use different aliases on the fields to fetch both if this was intentional.',
271
-
locations: [
272
-
{line: 4,column: 11},
273
-
{line: 7,column: 11},
274
-
],
275
-
},
276
-
]);
290
+
`).to.deep.equal([
291
+
{
292
+
message:
293
+
'Fields "name" conflict because they return conflicting types "String!" and "String". Use different aliases on the fields to fetch both if this was intentional.',
294
+
locations: [
295
+
{line: 4,column: 13},
296
+
{line: 7,column: 13},
297
+
],
298
+
},
299
+
]);
300
+
});
301
+
});
302
+
303
+
describe('allows same nullability on mutually exclusive types',()=>{
304
+
it('for optional and unset',()=>{
305
+
// this should be valid because name is nullable by default
306
+
expectValid(`
307
+
fragment conflictingNullability on Pet {
308
+
... on Dog {
309
+
name?
310
+
}
311
+
... on Cat {
312
+
name
313
+
}
314
+
}
315
+
`);
316
+
});
317
+
318
+
it('for optional and optional',()=>{
319
+
expectValid(`
320
+
fragment conflictingNullability on Pet {
321
+
... on Dog {
322
+
name?
323
+
}
324
+
... on Cat {
325
+
name?
326
+
}
327
+
}
328
+
`);
329
+
});
330
+
331
+
it('for unset and unset',()=>{
332
+
expectValid(`
333
+
fragment conflictingNullability on Pet {
334
+
... on Dog {
335
+
name
336
+
}
337
+
... on Cat {
338
+
name
339
+
}
340
+
}
341
+
`);
342
+
});
277
343
});
278
344
279
345
it('encounters conflict in fragments',()=>{
@@ -654,11 +720,7 @@ describe('Validate: Overlapping fields can be merged', () => {
654
720
});
655
721
656
722
describe('nullable field on types which potentially overlap',()=>{
657
-
it('matching nullability status',()=>{
658
-
// This is invalid since an object could potentially be both the Object
659
-
// type IntBox and the interface type NonNullStringBox1. While that
660
-
// condition does not exist in the current schema, the schema could
661
-
// expand in the future to allow this. Thus it is invalid.
723
+
it('matching required status',()=>{
662
724
expectValidWithSchema(
663
725
schema,
664
726
`
@@ -676,11 +738,61 @@ describe('Validate: Overlapping fields can be merged', () => {
676
738
);
677
739
});
678
740
679
-
it('conflicting nullability status',()=>{
680
-
// This is invalid since an object could potentially be both the Object
681
-
// type IntBox and the interface type NonNullStringBox1. While that
682
-
// condition does not exist in the current schema, the schema could
683
-
// expand in the future to allow this. Thus it is invalid.
741
+
it('matching optional status',()=>{
742
+
expectValidWithSchema(
743
+
schema,
744
+
`
745
+
{
746
+
someBox {
747
+
...on SomeBox {
748
+
unrelatedField?
749
+
}
750
+
...on IntBox {
751
+
unrelatedField?
752
+
}
753
+
}
754
+
}
755
+
`,
756
+
);
757
+
});
758
+
759
+
it('matching unset status',()=>{
760
+
expectValidWithSchema(
761
+
schema,
762
+
`
763
+
{
764
+
someBox {
765
+
...on SomeBox {
766
+
unrelatedField
767
+
}
768
+
...on IntBox {
769
+
unrelatedField
770
+
}
771
+
}
772
+
}
773
+
`,
774
+
);
775
+
});
776
+
777
+
it('matching optional and unset (optional) status',()=>{
778
+
expectValidWithSchema(
779
+
schema,
780
+
`
781
+
{
782
+
someBox {
783
+
...on SomeBox {
784
+
unrelatedField?
785
+
}
786
+
...on IntBox {
787
+
unrelatedField
788
+
}
789
+
}
790
+
}
791
+
`,
792
+
);
793
+
});
794
+
795
+
it('conflicting required and unset (optional) status',()=>{
684
796
expectErrorsWithSchema(
685
797
schema,
686
798
`
@@ -707,11 +819,34 @@ describe('Validate: Overlapping fields can be merged', () => {
707
819
]);
708
820
});
709
821
710
-
it('conflicting nullability status with aliases',()=>{
711
-
// This is invalid since an object could potentially be both the Object
712
-
// type IntBox and the interface type NonNullStringBox1. While that
713
-
// condition does not exist in the current schema, the schema could
714
-
// expand in the future to allow this. Thus it is invalid.
822
+
it('conflicting required and optional status',()=>{
823
+
expectErrorsWithSchema(
824
+
schema,
825
+
`
826
+
{
827
+
someBox {
828
+
...on SomeBox {
829
+
unrelatedField?
830
+
}
831
+
...on IntBox {
832
+
unrelatedField!
833
+
}
834
+
}
835
+
}
836
+
`,
837
+
).to.deep.equal([
838
+
{
839
+
message:
840
+
'Fields "unrelatedField" conflict because they return conflicting types "String" and "String!". Use different aliases on the fields to fetch both if this was intentional.',
841
+
locations: [
842
+
{line: 5,column: 19},
843
+
{line: 8,column: 19},
844
+
],
845
+
},
846
+
]);
847
+
});
848
+
849
+
it('conflicting required and unset (optional) status with aliases',()=>{
715
850
expectValidWithSchema(
716
851
schema,
717
852
`
@@ -728,6 +863,96 @@ describe('Validate: Overlapping fields can be merged', () => {
728
863
`,
729
864
);
730
865
});
866
+
867
+
it('conflicting required and optional status with aliases',()=>{
868
+
expectValidWithSchema(
869
+
schema,
870
+
`
871
+
{
872
+
someBox {
873
+
...on SomeBox {
874
+
nullable: unrelatedField!
875
+
}
876
+
...on IntBox {
877
+
nonNullable: unrelatedField?
878
+
}
879
+
}
880
+
}
881
+
`,
882
+
);
883
+
});
884
+
885
+
it('matching optional and unset (optional) status with aliases',()=>{
886
+
expectValidWithSchema(
887
+
schema,
888
+
`
889
+
{
890
+
someBox {
891
+
...on SomeBox {
892
+
unset: unrelatedField
893
+
}
894
+
...on IntBox {
895
+
nonNullable: unrelatedField?
896
+
}
897
+
}
898
+
}
899
+
`,
900
+
);
901
+
});
902
+
903
+
it('matching required and required status with aliases',()=>{
904
+
expectValidWithSchema(
905
+
schema,
906
+
`
907
+
{
908
+
someBox {
909
+
...on SomeBox {
910
+
otherNonnullable: unrelatedField!
911
+
}
912
+
...on IntBox {
913
+
nonNullable: unrelatedField!
914
+
}
915
+
}
916
+
}
917
+
`,
918
+
);
919
+
});
920
+
921
+
it('matching optional and optional status with aliases',()=>{
922
+
expectValidWithSchema(
923
+
schema,
924
+
`
925
+
{
926
+
someBox {
927
+
...on SomeBox {
928
+
nullable: unrelatedField?
929
+
}
930
+
...on IntBox {
931
+
otherNullable: unrelatedField?
932
+
}
933
+
}
934
+
}
935
+
`,
936
+
);
937
+
});
938
+
939
+
it('matching unset and unset status with aliases',()=>{
940
+
expectValidWithSchema(
941
+
schema,
942
+
`
943
+
{
944
+
someBox {
945
+
...on SomeBox {
946
+
unset: unrelatedField
947
+
}
948
+
...on IntBox {
949
+
otherUnset: unrelatedField
950
+
}
951
+
}
952
+
}
953
+
`,
954
+
);
955
+
});
731
956
});
732
957
733
958
describe('non-nullable field on types which potentially overlap',()=>{
0 commit comments