Skip to content

Commit

Permalink
Improve validation error message when field names conflict (#363)
Browse files Browse the repository at this point in the history
* Improve validation error message when field names conflict

* Remove extra hint and add unit test
  • Loading branch information
robzhu authored and leebyron committed Apr 26, 2016
1 parent 3dc0ddb commit 6103d2d
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
"babel-plugin-transform-runtime": "6.6.0",
"babel-preset-es2015": "6.6.0",
"chai": "3.5.0",
"chai-string": "1.2.0",
"chai-subset": "1.2.2",
"coveralls": "2.11.9",
"eslint": "2.7.0",
Expand Down
13 changes: 13 additions & 0 deletions src/validation/__tests__/OverlappingFieldsCanBeMerged-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
* of patent rights can be found in the PATENTS file in the same directory.
*/

import { expect } from 'chai';
import { describe, it } from 'mocha';
import {
expectPassesRule,
Expand All @@ -28,7 +29,10 @@ import {
GraphQLString,
GraphQLID,
} from '../../type';
import chai from 'chai';
import chaiString from 'chai-string';

chai.use(chaiString);

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

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

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

});

});
4 changes: 3 additions & 1 deletion src/validation/rules/OverlappingFieldsCanBeMerged.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ export function fieldsConflictMessage(
responseName: string,
reason: ConflictReasonMessage
): string {
return `Fields "${responseName}" conflict because ${reasonMessage(reason)}.`;
return `Fields "${responseName}" conflict because ${reasonMessage(reason)}` +
'. Use different aliases on the fields to fetch both if this was ' +
'intentional.';
}

function reasonMessage(reason: ConflictReasonMessage): string {
Expand Down

0 comments on commit 6103d2d

Please sign in to comment.