From 58453c31f78dc5c6d9cee00cd70f55dea471dbfb Mon Sep 17 00:00:00 2001 From: Daniel Tschinder Date: Sun, 11 Feb 2018 14:11:21 +0100 Subject: [PATCH] Improve validation error message when field names conflict ref: graphql/graphql-js#363 --- .../Rules/OverlappingFieldsCanBeMerged.php | 2 +- .../Validator/OverlappingFieldsCanBeMergedTest.php | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/Validator/Rules/OverlappingFieldsCanBeMerged.php b/src/Validator/Rules/OverlappingFieldsCanBeMerged.php index d0a0fb0..95b0e86 100644 --- a/src/Validator/Rules/OverlappingFieldsCanBeMerged.php +++ b/src/Validator/Rules/OverlappingFieldsCanBeMerged.php @@ -28,7 +28,7 @@ class OverlappingFieldsCanBeMerged extends AbstractValidationRule static function fieldsConflictMessage($responseName, $reason) { $reasonMessage = self::reasonMessage($reason); - return "Fields \"$responseName\" conflict because $reasonMessage."; + return "Fields \"$responseName\" conflict because $reasonMessage. Use different aliases on the fields to fetch both if this was intentional."; } static function reasonMessage($reason) diff --git a/tests/Validator/OverlappingFieldsCanBeMergedTest.php b/tests/Validator/OverlappingFieldsCanBeMergedTest.php index 4c65960..84bcf29 100644 --- a/tests/Validator/OverlappingFieldsCanBeMergedTest.php +++ b/tests/Validator/OverlappingFieldsCanBeMergedTest.php @@ -785,6 +785,19 @@ class OverlappingFieldsCanBeMergedTest extends TestCase '); } + /** + * @it error message contains hint for alias conflict + */ + public function testErrorMessageContainsHintForAliasConflict() + { + // The error template should end with a hint for the user to try using + // different aliases. + $error = OverlappingFieldsCanBeMerged::fieldsConflictMessage('x', 'a and b are different fields'); + $hint = 'Use different aliases on the fields to fetch both if this was intentional.'; + + $this->assertStringEndsWith($hint, $error); + } + private function getSchema() { $StringBox = null;