Skip to content

Commit

Permalink
Not sending variables if null (#19)
Browse files Browse the repository at this point in the history
* Not sending variables if null
  • Loading branch information
challgren authored and rccrdpccl committed Aug 16, 2018
1 parent 50e4621 commit d57e777
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
8 changes: 5 additions & 3 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,21 @@ public function __construct(ClientInterface $httpClient, ResponseBuilder $respon
* @throws \UnexpectedValueException When response body is not a valid json
* @throws \RuntimeException When there are transfer errors
*/
public function query(string $query, array $variables = []): Response
public function query(string $query, array $variables = null): Response
{
$options = [
'json' => [
'query' => $query,
'variables' => $variables,
],
];
if (!is_null($variables)) {
$options['json']['variables'] = $variables;
}

try {
$response = $this->httpClient->request('POST', '', $options);
} catch (TransferException $e) {
throw new \RuntimeException('Network Error.'.$e->getMessage(), 0, $e);
throw new \RuntimeException('Network Error.' . $e->getMessage(), 0, $e);
}

return $this->responseBuilder->build($response);
Expand Down
2 changes: 0 additions & 2 deletions tests/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ public function testSimpleQueryWhenInvalidJsonIsReceived()
[
'json' => [
'query' => $query,
'variables' => [],
],
]
)
Expand Down Expand Up @@ -109,7 +108,6 @@ public function testSimpleQuery()
[
'json' => [
'query' => $query,
'variables' => [],
],
]
)
Expand Down

0 comments on commit d57e777

Please sign in to comment.