Server: do not raise an error when variables are passed as empty string (#156)

This commit is contained in:
Vladimir Razuvaev 2017-08-30 23:26:45 +07:00
parent 46477c75c4
commit 6ff427d241
2 changed files with 24 additions and 0 deletions

View File

@ -71,6 +71,10 @@ class OperationParams
'variables' => null
];
if ($params['variables'] === "") {
$params['variables'] = null;
}
if (is_string($params['variables'])) {
$tmp = json_decode($params['variables'], true);
if (!json_last_error()) {

View File

@ -99,6 +99,26 @@ class RequestValidationTest extends \PHPUnit_Framework_TestCase
);
}
/**
* @see https://github.com/webonyx/graphql-php/issues/156
*/
public function testIgnoresNullAndEmptyStringVariables()
{
$query = '{my q}';
$parsedBody = OperationParams::create([
'query' => $query,
'variables' => null
]);
$this->assertValid($parsedBody);
$variables = "";
$parsedBody = OperationParams::create([
'query' => $query,
'variables' => $variables
]);
$this->assertValid($parsedBody);
}
public function testFailsWhenVariablesParameterIsNotObject()
{
$parsedBody = OperationParams::create([