mirror of
https://github.com/retailcrm/graphql-php.git
synced 2025-02-16 20:33:14 +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
|
'variables' => null
|
||||||
];
|
];
|
||||||
|
|
||||||
|
if ($params['variables'] === "") {
|
||||||
|
$params['variables'] = null;
|
||||||
|
}
|
||||||
|
|
||||||
if (is_string($params['variables'])) {
|
if (is_string($params['variables'])) {
|
||||||
$tmp = json_decode($params['variables'], true);
|
$tmp = json_decode($params['variables'], true);
|
||||||
if (!json_last_error()) {
|
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()
|
public function testFailsWhenVariablesParameterIsNotObject()
|
||||||
{
|
{
|
||||||
$parsedBody = OperationParams::create([
|
$parsedBody = OperationParams::create([
|
||||||
|
Loading…
x
Reference in New Issue
Block a user