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' => [], ], ] )