Skip to content

Commit 6ff427d

Browse files
committed
Server: do not raise an error when variables are passed as empty string (#156)
1 parent 46477c7 commit 6ff427d

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

src/Server/OperationParams.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,10 @@ public static function create(array $params, $readonly = false)
7171
'variables' => null
7272
];
7373

74+
if ($params['variables'] === "") {
75+
$params['variables'] = null;
76+
}
77+
7478
if (is_string($params['variables'])) {
7579
$tmp = json_decode($params['variables'], true);
7680
if (!json_last_error()) {

tests/Server/RequestValidationTest.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,26 @@ public function testFailsWhenOperationParameterIsNotString()
9999
);
100100
}
101101

102+
/**
103+
* @see https://github.com/webonyx/graphql-php/issues/156
104+
*/
105+
public function testIgnoresNullAndEmptyStringVariables()
106+
{
107+
$query = '{my q}';
108+
$parsedBody = OperationParams::create([
109+
'query' => $query,
110+
'variables' => null
111+
]);
112+
$this->assertValid($parsedBody);
113+
114+
$variables = "";
115+
$parsedBody = OperationParams::create([
116+
'query' => $query,
117+
'variables' => $variables
118+
]);
119+
$this->assertValid($parsedBody);
120+
}
121+
102122
public function testFailsWhenVariablesParameterIsNotObject()
103123
{
104124
$parsedBody = OperationParams::create([

0 commit comments

Comments
 (0)