Skip to content

Commit d57e777

Browse files
challgrenrccrdpccl
authored andcommitted
Not sending variables if null (#19)
* Not sending variables if null
1 parent 50e4621 commit d57e777

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

src/Client.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,21 @@ public function __construct(ClientInterface $httpClient, ResponseBuilder $respon
2020
* @throws \UnexpectedValueException When response body is not a valid json
2121
* @throws \RuntimeException When there are transfer errors
2222
*/
23-
public function query(string $query, array $variables = []): Response
23+
public function query(string $query, array $variables = null): Response
2424
{
2525
$options = [
2626
'json' => [
2727
'query' => $query,
28-
'variables' => $variables,
2928
],
3029
];
30+
if (!is_null($variables)) {
31+
$options['json']['variables'] = $variables;
32+
}
3133

3234
try {
3335
$response = $this->httpClient->request('POST', '', $options);
3436
} catch (TransferException $e) {
35-
throw new \RuntimeException('Network Error.'.$e->getMessage(), 0, $e);
37+
throw new \RuntimeException('Network Error.' . $e->getMessage(), 0, $e);
3638
}
3739

3840
return $this->responseBuilder->build($response);

tests/ClientTest.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ public function testSimpleQueryWhenInvalidJsonIsReceived()
7070
[
7171
'json' => [
7272
'query' => $query,
73-
'variables' => [],
7473
],
7574
]
7675
)
@@ -109,7 +108,6 @@ public function testSimpleQuery()
109108
[
110109
'json' => [
111110
'query' => $query,
112-
'variables' => [],
113111
],
114112
]
115113
)

0 commit comments

Comments
 (0)