diff --git a/package.json b/package.json index c8d24cee72..b8f5c03e4b 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/validation/__tests__/OverlappingFieldsCanBeMerged-test.js b/src/validation/__tests__/OverlappingFieldsCanBeMerged-test.js index 457a0dad05..65e329601e 100644 --- a/src/validation/__tests__/OverlappingFieldsCanBeMerged-test.js +++ b/src/validation/__tests__/OverlappingFieldsCanBeMerged-test.js @@ -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, @@ -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', () => { @@ -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); + }); + }); }); diff --git a/src/validation/rules/OverlappingFieldsCanBeMerged.js b/src/validation/rules/OverlappingFieldsCanBeMerged.js index 2c2c8edcab..38c506ddca 100644 --- a/src/validation/rules/OverlappingFieldsCanBeMerged.js +++ b/src/validation/rules/OverlappingFieldsCanBeMerged.js @@ -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 {