Skip to content

Commit 7398dcf

Browse files
committed
add exclusive types tests
1 parent 306c730 commit 7398dcf

File tree

1 file changed

+164
-0
lines changed

1 file changed

+164
-0
lines changed

src/validation/__tests__/OverlappingFieldsCanBeMergedRule-test.ts

Lines changed: 164 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1101,6 +1101,170 @@ describe('Validate: Overlapping fields can be merged', () => {
11011101
});
11021102
});
11031103

1104+
describe('Exclusive types without aliases', () => {
1105+
it('conflicting optional and required nullability status', () =>{
1106+
expectErrorsWithSchema(
1107+
schema,
1108+
`
1109+
{
1110+
someBox {
1111+
... on IntBox {
1112+
scalar!
1113+
}
1114+
... on StringBox {
1115+
scalar?
1116+
}
1117+
}
1118+
}
1119+
`
1120+
).to.deep.equal([
1121+
{
1122+
message:
1123+
'Fields "scalar" conflict because they return conflicting types "Int!" and "String". Use different aliases on the fields to fetch both if this was intentional.',
1124+
locations: [
1125+
{ line: 5, column: 19 },
1126+
{ line: 8, column: 19 },
1127+
],
1128+
},
1129+
]);
1130+
});
1131+
1132+
it('matching optional and optional nullability status', () =>{
1133+
expectErrorsWithSchema(
1134+
schema,
1135+
`
1136+
{
1137+
someBox {
1138+
... on IntBox {
1139+
scalar?
1140+
}
1141+
... on StringBox {
1142+
scalar?
1143+
}
1144+
}
1145+
}
1146+
`
1147+
).to.deep.equal([
1148+
{
1149+
message:
1150+
'Fields "scalar" conflict because they return conflicting types "Int" and "String". Use different aliases on the fields to fetch both if this was intentional.',
1151+
locations: [
1152+
{ line: 5, column: 19 },
1153+
{ line: 8, column: 19 },
1154+
],
1155+
},
1156+
]);
1157+
});
1158+
1159+
it('matching required and required nullability status', () =>{
1160+
expectErrorsWithSchema(
1161+
schema,
1162+
`
1163+
{
1164+
someBox {
1165+
... on IntBox {
1166+
scalar!
1167+
}
1168+
... on StringBox {
1169+
scalar!
1170+
}
1171+
}
1172+
}
1173+
`
1174+
).to.deep.equal([
1175+
{
1176+
message:
1177+
'Fields "scalar" conflict because they return conflicting types "Int!" and "String!". Use different aliases on the fields to fetch both if this was intentional.',
1178+
locations: [
1179+
{ line: 5, column: 19 },
1180+
{ line: 8, column: 19 },
1181+
],
1182+
},
1183+
]);
1184+
});
1185+
1186+
it('conflicting unset (optional) and required nullability status', () =>{
1187+
expectErrorsWithSchema(
1188+
schema,
1189+
`
1190+
{
1191+
someBox {
1192+
... on IntBox {
1193+
scalar
1194+
}
1195+
... on StringBox {
1196+
scalar!
1197+
}
1198+
}
1199+
}
1200+
`
1201+
).to.deep.equal([
1202+
{
1203+
message:
1204+
'Fields "scalar" conflict because they return conflicting types "Int" and "String!". Use different aliases on the fields to fetch both if this was intentional.',
1205+
locations: [
1206+
{ line: 5, column: 19 },
1207+
{ line: 8, column: 19 },
1208+
],
1209+
},
1210+
]);
1211+
});
1212+
1213+
it('matching unset (optional) and optional nullability status', () =>{
1214+
expectErrorsWithSchema(
1215+
schema,
1216+
`
1217+
{
1218+
someBox {
1219+
... on IntBox {
1220+
scalar
1221+
}
1222+
... on StringBox {
1223+
scalar?
1224+
}
1225+
}
1226+
}
1227+
`
1228+
).to.deep.equal([
1229+
{
1230+
message:
1231+
'Fields "scalar" conflict because they return conflicting types "Int" and "String". Use different aliases on the fields to fetch both if this was intentional.',
1232+
locations: [
1233+
{ line: 5, column: 19 },
1234+
{ line: 8, column: 19 },
1235+
],
1236+
},
1237+
]);
1238+
});
1239+
1240+
it('matching unset (optional) and unset (optional) nullability status', () =>{
1241+
expectErrorsWithSchema(
1242+
schema,
1243+
`
1244+
{
1245+
someBox {
1246+
... on IntBox {
1247+
scalar
1248+
}
1249+
... on StringBox {
1250+
scalar
1251+
}
1252+
}
1253+
}
1254+
`
1255+
).to.deep.equal([
1256+
{
1257+
message:
1258+
'Fields "scalar" conflict because they return conflicting types "Int" and "String". Use different aliases on the fields to fetch both if this was intentional.',
1259+
locations: [
1260+
{ line: 5, column: 19 },
1261+
{ line: 8, column: 19 },
1262+
],
1263+
},
1264+
]);
1265+
});
1266+
});
1267+
11041268
it('compatible return shapes on different return types', () => {
11051269
// In this case `deepBox` returns `SomeBox` in the first usage, and
11061270
// `StringBox` in the second usage. These return types are not the same!

0 commit comments

Comments
 (0)