Skip to content

Validation: improving overlapping fields quality #386

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 10, 2016
Merged
Show file tree
Hide file tree
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
165 changes: 157 additions & 8 deletions src/validation/__tests__/OverlappingFieldsCanBeMerged-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -247,10 +247,10 @@ describe('Validate: Overlapping fields can be merged', () => {
`, [
{ message: fieldsConflictMessage('x', 'a and b are different fields'),
locations: [ { line: 18, column: 9 }, { line: 21, column: 9 } ] },
{ message: fieldsConflictMessage('x', 'a and c are different fields'),
locations: [ { line: 18, column: 9 }, { line: 14, column: 11 } ] },
{ message: fieldsConflictMessage('x', 'b and c are different fields'),
locations: [ { line: 21, column: 9 }, { line: 14, column: 11 } ] }
{ message: fieldsConflictMessage('x', 'c and a are different fields'),
locations: [ { line: 14, column: 11 }, { line: 18, column: 9 } ] },
{ message: fieldsConflictMessage('x', 'c and b are different fields'),
locations: [ { line: 14, column: 11 }, { line: 21, column: 9 } ] }
]);
});

Expand Down Expand Up @@ -363,6 +363,97 @@ describe('Validate: Overlapping fields can be merged', () => {
]);
});

it('reports deep conflict to nearest common ancestor in fragments', () => {
expectFailsRule(OverlappingFieldsCanBeMerged, `
{
field {
...F
}
field {
...F
}
}
fragment F on T {
deepField {
deeperField {
x: a
}
deeperField {
x: b
}
},
deepField {
deeperField {
y
}
}
}
`, [
{ message: fieldsConflictMessage(
'deeperField', [ [ 'x', 'a and b are different fields' ] ]
),
locations: [
{ line: 12, column: 11 },
{ line: 13, column: 13 },
{ line: 15, column: 11 },
{ line: 16, column: 13 } ] },
]);
});

it('reports deep conflict in nested fragments', () => {
expectFailsRule(OverlappingFieldsCanBeMerged, `
{
field {
...F
}
field {
...I
}
}
fragment F on T {
x: a
...G
}
fragment G on T {
y: c
}
fragment I on T {
y: d
...J
}
fragment J on T {
x: b
}
`, [
{ message: fieldsConflictMessage(
'field', [ [ 'x', 'a and b are different fields' ],
[ 'y', 'c and d are different fields' ] ]
),
locations: [
{ line: 3, column: 9 },
{ line: 11, column: 9 },
{ line: 15, column: 9 },
{ line: 6, column: 9 },
{ line: 22, column: 9 },
{ line: 18, column: 9 } ] },
]);
});

it('ignores unknown fragments', () => {
expectPassesRule(OverlappingFieldsCanBeMerged, `
{
field
...Unknown
...Known
}

fragment Known on T {
field
...OtherUnknown
}
`);
});

describe('return types must be unambiguous', () => {

const SomeBox = new GraphQLInterfaceType({
Expand Down Expand Up @@ -537,6 +628,64 @@ describe('Validate: Overlapping fields can be merged', () => {
]);
});

it('reports correctly when a non-exclusive follows an exclusive', () => {
expectFailsRuleWithSchema(schema, OverlappingFieldsCanBeMerged, `
{
someBox {
... on IntBox {
deepBox {
...X
}
}
}
someBox {
... on StringBox {
deepBox {
...Y
}
}
}
memoed: someBox {
... on IntBox {
deepBox {
...X
}
}
}
memoed: someBox {
... on StringBox {
deepBox {
...Y
}
}
}
other: someBox {
...X
}
other: someBox {
...Y
}
}
fragment X on SomeBox {
scalar
}
fragment Y on SomeBox {
scalar: unrelatedField
}
`, [
{ message: fieldsConflictMessage(
'other',
[ [ 'scalar', 'scalar and unrelatedField are different fields' ] ]
),
locations: [
{ line: 31, column: 11 },
{ line: 39, column: 11 },
{ line: 34, column: 11 },
{ line: 42, column: 11 },
] }
]);
});

it('disallows differing return type nullability despite no overlap', () => {
expectFailsRuleWithSchema(schema, OverlappingFieldsCanBeMerged, `
{
Expand Down Expand Up @@ -725,15 +874,15 @@ describe('Validate: Overlapping fields can be merged', () => {
`, [
{ message: fieldsConflictMessage(
'edges',
[ [ 'node', [ [ 'id', 'id and name are different fields' ] ] ] ]
[ [ 'node', [ [ 'id', 'name and id are different fields' ] ] ] ]
),
locations: [
{ line: 14, column: 11 },
{ line: 15, column: 13 },
{ line: 16, column: 15 },
{ line: 5, column: 13 },
{ line: 6, column: 15 },
{ line: 7, column: 17 },
{ line: 14, column: 11 },
{ line: 15, column: 13 },
{ line: 16, column: 15 },
] }
]);
});
Expand Down
Loading