mirror of
https://github.com/retailcrm/graphql-php.git
synced 2024-11-22 04:46:04 +03:00
Server: do not raise an error when variables are passed as empty string (#156)
This commit is contained in:
parent
46477c75c4
commit
6ff427d241
@ -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()) {
|
||||
|
@ -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([
|
||||
|
Loading…
Reference in New Issue
Block a user