From d57e7772eb354b31d358cf35b3b14adba877fcd7 Mon Sep 17 00:00:00 2001 From: Chris Hallgren Date: Thu, 16 Aug 2018 04:13:17 -0500 Subject: [PATCH] Not sending variables if null (#19) * Not sending variables if null --- src/Client.php | 8 +++++--- tests/ClientTest.php | 2 -- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Client.php b/src/Client.php index bcaacac..671bade 100644 --- a/src/Client.php +++ b/src/Client.php @@ -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); diff --git a/tests/ClientTest.php b/tests/ClientTest.php index bc28586..44a090a 100644 --- a/tests/ClientTest.php +++ b/tests/ClientTest.php @@ -70,7 +70,6 @@ public function testSimpleQueryWhenInvalidJsonIsReceived() [ 'json' => [ 'query' => $query, - 'variables' => [], ], ] ) @@ -109,7 +108,6 @@ public function testSimpleQuery() [ 'json' => [ 'query' => $query, - 'variables' => [], ], ] )