From 36a7ab84dff2fe844eeeb07678704c128f215662 Mon Sep 17 00:00:00 2001 From: Yaacov Rydzinski Date: Sun, 26 Jul 2026 17:40:18 +0300 Subject: [PATCH] polish(OverlappingFieldsCanMerge: add tests documenting existing behavior subfield conflict detection is short-circuited by parent conflicts --- .../OverlappingFieldsCanBeMergedRule-test.ts | 110 ++++++++++++++++++ 1 file changed, 110 insertions(+) diff --git a/src/validation/__tests__/OverlappingFieldsCanBeMergedRule-test.ts b/src/validation/__tests__/OverlappingFieldsCanBeMergedRule-test.ts index ac7cf7991e..7fed134458 100644 --- a/src/validation/__tests__/OverlappingFieldsCanBeMergedRule-test.ts +++ b/src/validation/__tests__/OverlappingFieldsCanBeMergedRule-test.ts @@ -570,6 +570,87 @@ describe('Validate: Overlapping fields can be merged', () => { ]); }); + it('does not compare subfields of incompatible parent calls', () => { + expectErrors(` + fragment incompatibleParents on Dog { + parent: mother { + value: name + } + parent: father { + value: mother { name } + } + } + `).toDeepEqual([ + { + message: + 'Fields "parent" conflict because "mother" and "father" are different fields. Use different aliases on the fields to fetch both if this was intentional.', + locations: [ + { line: 3, column: 9 }, + { line: 6, column: 9 }, + ], + }, + ]); + }); + + it('still compares subfields of each compatible parent-call group', () => { + expectErrors(` + fragment mixedParents on Dog { + parent: mother { + value: name + } + parent: mother { + value: mother { name } + } + parent: father { name } + } + `).toDeepEqual([ + { + message: + 'Fields "parent" conflict because subfields "value" conflict because "name" and "mother" are different fields. Use different aliases on the fields to fetch both if this was intentional.', + locations: [ + { line: 3, column: 9 }, + { line: 4, column: 11 }, + { line: 6, column: 9 }, + { line: 7, column: 11 }, + ], + }, + { + message: + 'Fields "parent" conflict because "mother" and "father" are different fields. Use different aliases on the fields to fetch both if this was intentional.', + locations: [ + { line: 3, column: 9 }, + { line: 9, column: 9 }, + ], + }, + { + message: + 'Fields "parent" conflict because "mother" and "father" are different fields. Use different aliases on the fields to fetch both if this was intentional.', + locations: [ + { line: 6, column: 9 }, + { line: 9, column: 9 }, + ], + }, + ]); + }); + + it('does not compare subfields after a stream conflict', () => { + expectErrors(` + fragment streamBarrier on Dog { + parent: mother @stream { value: name } + parent: mother { value: father } + } + `).toDeepEqual([ + { + message: + 'Fields "parent" conflict because they have overlapping stream directives. Use different aliases on the fields to fetch both if this was intentional.', + locations: [ + { line: 3, column: 9 }, + { line: 4, column: 9 }, + ], + }, + ]); + }); + it('very deep conflict', () => { expectErrors(` { @@ -763,6 +844,7 @@ describe('Validate: Overlapping fields can be merged', () => { scalar: String deepBox: StringBox unrelatedField: String + listNode: [Node] listStringBox: [StringBox] stringBox: StringBox intBox: IntBox @@ -772,6 +854,7 @@ describe('Validate: Overlapping fields can be merged', () => { scalar: Int deepBox: IntBox unrelatedField: String + node: Node listStringBox: [StringBox] stringBox: StringBox intBox: IntBox @@ -899,6 +982,33 @@ describe('Validate: Overlapping fields can be merged', () => { ]); }); + it('does not compare subfields after a response-type conflict', () => { + expectErrorsWithSchema( + schema, + ` + { + someBox { + ... on StringBox { + parent: listNode { value: name } + } + ... on IntBox { + parent: node { value: id } + } + } + } + `, + ).toDeepEqual([ + { + message: + 'Fields "parent" conflict because they return conflicting types "[Node]" and "Node". Use different aliases on the fields to fetch both if this was intentional.', + locations: [ + { line: 5, column: 17 }, + { line: 8, column: 17 }, + ], + }, + ]); + }); + it('reports correctly when a non-exclusive follows an exclusive', () => { expectErrorsWithSchema( schema,