diff --git a/src/CrowdinApiClient/Api/GraphqlApi.php b/src/CrowdinApiClient/Api/GraphqlApi.php index 2d155a8b..eb6ed0b4 100644 --- a/src/CrowdinApiClient/Api/GraphqlApi.php +++ b/src/CrowdinApiClient/Api/GraphqlApi.php @@ -33,7 +33,8 @@ public function query(string $query, ?string $operationName = null, ?array $vari ]; $response = $this->client->getClient()->request('post', $this->getFullUrl(), $options); - $response = json_decode($response, true); + // GuzzleHttpClient returns a stream, not a string + $response = json_decode((string)$response, true); $this->client->getResponseErrorHandler()->check($response); diff --git a/tests/CrowdinApiClient/Api/GraphqlApiTest.php b/tests/CrowdinApiClient/Api/GraphqlApiTest.php index 1b30ac30..dd2044e0 100644 --- a/tests/CrowdinApiClient/Api/GraphqlApiTest.php +++ b/tests/CrowdinApiClient/Api/GraphqlApiTest.php @@ -2,8 +2,24 @@ namespace CrowdinApiClient\Tests\Api; +use CrowdinApiClient\Http\Client\GuzzleHttpClient; +use GuzzleHttp\Client; +use GuzzleHttp\Handler\MockHandler; +use GuzzleHttp\Psr7\Response; + class GraphqlApiTest extends AbstractTestApi { + public function testQueryWithGuzzleClient(): void + { + $responseBody = json_encode(['data' => ['viewer' => ['id' => 1]]]); + $handler = new MockHandler([new Response(200, [], $responseBody)]); + $this->crowdin->setClient(new GuzzleHttpClient(new Client(['handler' => $handler]))); + + $response = $this->crowdin->graphql->query('query { viewer { id } }'); + + $this->assertSame(['viewer' => ['id' => 1]], $response); + } + public function testQuery(): void { $query = 'query Test($limit: Int) {