Skip to content

Commit 93ca185

Browse files
committed
Merge branch 'feat-adapters' of github.com:utopia-php/fetch into feat-adapters
2 parents 59088bb + c6e1292 commit 93ca185

3 files changed

Lines changed: 6 additions & 6 deletions

File tree

.github/workflows/tests.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@ jobs:
2929

3030
- name: Start Server
3131
run: |
32-
docker compose up -d
33-
sleep 5
32+
docker compose up -d --wait --wait-timeout 30
3433
3534
- name: Run Tests
3635
run: docker compose exec -T php vendor/bin/phpunit --configuration phpunit.xml

src/Adapter/Swoole.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
use Utopia\Fetch\Options\Swoole as SwooleOptions;
1616
use Utopia\Fetch\Response;
1717

18+
use function Swoole\Coroutine\run;
19+
1820
/**
1921
* Swoole Adapter
2022
* HTTP adapter using Swoole's HTTP client
@@ -261,7 +263,7 @@ private function executeRequest(
261263

262264
if (!$success) {
263265
$errorCode = $client->errCode;
264-
$errorMsg = socket_strerror($errorCode);
266+
$errorMsg = $client->errMsg;
265267
$this->closeClient($host, $port, $ssl);
266268
throw new Exception("Request failed: {$errorMsg} (Code: {$errorCode})");
267269
}
@@ -367,8 +369,7 @@ public function send(
367369
$response = null;
368370
$exception = null;
369371

370-
$coRun = 'Swoole\\Coroutine\\run';
371-
$coRun(function () use ($url, $method, $body, $headers, $options, $chunkCallback, &$response, &$exception) {
372+
run(function () use ($url, $method, $body, $headers, $options, $chunkCallback, &$response, &$exception) {
372373
try {
373374
$response = $this->executeRequest($url, $method, $body, $headers, $options, $chunkCallback);
374375
} catch (Throwable $e) {

src/Client.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ public function fetch(
297297
$body = match ($this->headers['content-type']) {
298298
self::CONTENT_TYPE_APPLICATION_JSON => $this->jsonEncode($body),
299299
self::CONTENT_TYPE_APPLICATION_FORM_URLENCODED, self::CONTENT_TYPE_MULTIPART_FORM_DATA => self::flatten($body),
300-
self::CONTENT_TYPE_GRAPHQL => isset($body['query']) && is_string($body['query']) ? $body['query'] : throw new Exception('GraphQL body must contain a "query" field with a string value'),
300+
self::CONTENT_TYPE_GRAPHQL => isset($body['query']) && is_string($body['query']) ? $body['query'] : $this->jsonEncode($body),
301301
default => $body,
302302
};
303303
}

0 commit comments

Comments
 (0)