Improve validation error message when field names conflict

ref: graphql/graphql-js#363
This commit is contained in:
Daniel Tschinder 2018-02-11 14:11:21 +01:00
parent d70a9a5e53
commit 58453c31f7
2 changed files with 14 additions and 1 deletions

View File

@ -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)

View File

@ -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;