Skip to content

Commit 6103d2d

Browse files
robzhuleebyron
authored andcommitted
Improve validation error message when field names conflict (#363)
* Improve validation error message when field names conflict * Remove extra hint and add unit test
1 parent 3dc0ddb commit 6103d2d

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
"babel-plugin-transform-runtime": "6.6.0",
6262
"babel-preset-es2015": "6.6.0",
6363
"chai": "3.5.0",
64+
"chai-string": "1.2.0",
6465
"chai-subset": "1.2.2",
6566
"coveralls": "2.11.9",
6667
"eslint": "2.7.0",

src/validation/__tests__/OverlappingFieldsCanBeMerged-test.js

+13
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
* of patent rights can be found in the PATENTS file in the same directory.
88
*/
99

10+
import { expect } from 'chai';
1011
import { describe, it } from 'mocha';
1112
import {
1213
expectPassesRule,
@@ -28,7 +29,10 @@ import {
2829
GraphQLString,
2930
GraphQLID,
3031
} from '../../type';
32+
import chai from 'chai';
33+
import chaiString from 'chai-string';
3134

35+
chai.use(chaiString);
3236

3337
describe('Validate: Overlapping fields can be merged', () => {
3438

@@ -753,6 +757,15 @@ describe('Validate: Overlapping fields can be merged', () => {
753757
`);
754758
});
755759

760+
it('error message contains hint for alias conflict', () => {
761+
// The error template should end with a hint for the user to try using
762+
// different aliases.
763+
const error = fieldsConflictMessage('x', 'a and b are different fields');
764+
const hint = 'Use different aliases on the fields to fetch both ' +
765+
'if this was intentional.';
766+
expect(error).to.endsWith(hint);
767+
});
768+
756769
});
757770

758771
});

src/validation/rules/OverlappingFieldsCanBeMerged.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,9 @@ export function fieldsConflictMessage(
3939
responseName: string,
4040
reason: ConflictReasonMessage
4141
): string {
42-
return `Fields "${responseName}" conflict because ${reasonMessage(reason)}.`;
42+
return `Fields "${responseName}" conflict because ${reasonMessage(reason)}` +
43+
'. Use different aliases on the fields to fetch both if this was ' +
44+
'intentional.';
4345
}
4446

4547
function reasonMessage(reason: ConflictReasonMessage): string {

0 commit comments

Comments
 (0)