Skip to content

Commit 33fd7fb

Browse files
committed
Add fragment argument overlap logic to OverlappingFieldsCanBeMerged
1 parent 2e4a9bc commit 33fd7fb

File tree

2 files changed

+365
-181
lines changed

2 files changed

+365
-181
lines changed

src/validation/__tests__/OverlappingFieldsCanBeMergedRule-test.ts

+59
Original file line numberDiff line numberDiff line change
@@ -1246,4 +1246,63 @@ describe('Validate: Overlapping fields can be merged', () => {
12461246
},
12471247
]);
12481248
});
1249+
1250+
describe('fragment arguments must produce fields that can be merged', () => {
1251+
it('encounters conflict in fragments', () => {
1252+
expectErrors(`
1253+
{
1254+
...WithArgs(x: 3)
1255+
...WithArgs(x: 4)
1256+
}
1257+
fragment WithArgs($x: Int) on Type {
1258+
a(x: $x)
1259+
}
1260+
`).toDeepEqual([
1261+
{
1262+
message:
1263+
'Spreads "WithArgs" conflict because WithArgs(x: 3) and WithArgs(x: 4) have different fragment arguments.',
1264+
locations: [
1265+
{ line: 3, column: 11 },
1266+
{ line: 4, column: 11 },
1267+
],
1268+
},
1269+
]);
1270+
});
1271+
it('encounters nested conflict in fragments', () => {
1272+
expectErrors(`
1273+
{
1274+
connection {
1275+
edges {
1276+
...WithArgs(x: 3)
1277+
}
1278+
}
1279+
...Connection
1280+
}
1281+
1282+
fragment Connection on Type {
1283+
connection {
1284+
edges {
1285+
...WithArgs(x: 4)
1286+
}
1287+
}
1288+
}
1289+
fragment WithArgs($x: Int) on Type {
1290+
a(x: $x)
1291+
}
1292+
`).toDeepEqual([
1293+
{
1294+
message:
1295+
'Fields "connection" conflict because subfields "edges" conflict because child spreads "WithArgs" conflict because WithArgs(x: 3) and WithArgs(x: 4) have different fragment arguments. Use different aliases on the fields to fetch both if this was intentional.',
1296+
locations: [
1297+
{ line: 3, column: 11 },
1298+
{ line: 4, column: 13 },
1299+
{ line: 5, column: 15 },
1300+
{ line: 12, column: 11 },
1301+
{ line: 13, column: 13 },
1302+
{ line: 14, column: 15 },
1303+
],
1304+
},
1305+
]);
1306+
});
1307+
});
12491308
});

0 commit comments

Comments
 (0)