Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
110 changes: 110 additions & 0 deletions src/validation/__tests__/OverlappingFieldsCanBeMergedRule-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(`
{
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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,
Expand Down
Loading