Skip to content

Commit

Permalink
Put null handling into the methods, not the transformer
Browse files Browse the repository at this point in the history
  • Loading branch information
xHeaven committed Jan 24, 2025
1 parent f9a9387 commit f31debc
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
10 changes: 5 additions & 5 deletions src/GraphQLClientMethods.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public function query(string $query, bool $withExtensions = false, bool $detaile
$response = $this->makeQueryRequest($query, $withExtensions, $detailedCost);

/** @var array $response */
$response = $withExtensions ? $response : data_get($response, 'data');
$response = $withExtensions ? $response : data_get($response, 'data', []);

return new GraphQLClientTransformer(
data: array_filter($response)
Expand All @@ -78,7 +78,7 @@ public function mutate(string $query, array $variables, bool $withExtensions = f
$response = $this->makeMutationRequest($query, $variables, $withExtensions, $detailedCost);

/** @var array $response */
$response = $withExtensions ? $response : data_get($response, 'data');
$response = $withExtensions ? $response : data_get($response, 'data', []);

return new GraphQLClientTransformer(
data: array_filter($response)
Expand All @@ -90,7 +90,7 @@ public function getCurrentBulkOperation(): GraphQLClientTransformer
$response = $this->makeGetCurrentBulkOperationRequest();

/** @var array $response */
$response = data_get($response, 'data.currentBulkOperation');
$response = data_get($response, 'data.currentBulkOperation', []);

return new GraphQLClientTransformer(
data: $response
Expand All @@ -102,7 +102,7 @@ public function createBulkOperation(string $query): GraphQLClientTransformer
$response = $this->makeCreateBulkOperationRequest($query);

/** @var array $response */
$response = data_get($response, 'data.bulkOperationRunQuery');
$response = data_get($response, 'data.bulkOperationRunQuery', []);

return new GraphQLClientTransformer(
data: $response
Expand All @@ -114,7 +114,7 @@ public function cancelBulkOperation(): GraphQLClientTransformer
$response = $this->makeCancelBulkOperationRequest();

/** @var array $response */
$response = data_get($response, 'data.bulkOperationCancel');
$response = data_get($response, 'data.bulkOperationCancel', []);

return new GraphQLClientTransformer(
data: $response
Expand Down
6 changes: 3 additions & 3 deletions src/GraphQLClientTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@

readonly class GraphQLClientTransformer
{
public function __construct(private ?array $data) {}
public function __construct(private array $data) {}

public function toArray(): ?array
public function toArray(): array
{
return $this->data;
}

public function toFluent(): Fluent
{
return fluent($this->data ?? []);
return fluent($this->data);
}

public function toCollection(): Collection
Expand Down

0 comments on commit f31debc

Please sign in to comment.