Skip to content

Commit 62d47d2

Browse files
committed
refactor: remove Arr::get use where there's cler no benefit
Arr:get does a lot of magic but there's no point using it when we don't need that magic.
1 parent 5985031 commit 62d47d2

File tree

5 files changed

+15
-20
lines changed

5 files changed

+15
-20
lines changed

src/GraphQL.php

+8-9
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
use GraphQL\Error\Debug;
1010
use GraphQL\Error\Error;
1111
use GraphQL\Type\Schema;
12-
use Illuminate\Support\Arr;
1312
use GraphQL\Error\FormattedError;
1413
use GraphQL\Type\Definition\Type;
1514
use GraphQL\GraphQL as GraphQLBase;
@@ -64,9 +63,9 @@ public function schema($schema = null): Schema
6463
return $schema;
6564
}
6665

67-
$schemaQuery = Arr::get($schema, 'query', []);
68-
$schemaMutation = Arr::get($schema, 'mutation', []);
69-
$schemaSubscription = Arr::get($schema, 'subscription', []);
66+
$schemaQuery = $schema['query'] ?? [];
67+
$schemaMutation = $schema['mutation'] ?? [];
68+
$schemaSubscription = $schema['subscription'] ?? [];
7069

7170
$query = $this->objectType($schemaQuery, [
7271
'name' => 'Query',
@@ -86,7 +85,7 @@ public function schema($schema = null): Schema
8685
'subscription' => ! empty($schemaSubscription) ? $subscription : null,
8786
'types' => function () use ($schema) {
8887
$types = [];
89-
$schemaTypes = Arr::get($schema, 'types', []);
88+
$schemaTypes = $schema['types'] ?? [];
9089

9190
if ($schemaTypes) {
9291
foreach ($schemaTypes as $name => $type) {
@@ -131,10 +130,10 @@ public function query(string $query, ?array $params = [], array $opts = []): arr
131130
*/
132131
public function queryAndReturnResult(string $query, ?array $params = [], array $opts = []): ExecutionResult
133132
{
134-
$context = Arr::get($opts, 'context');
135-
$schemaName = Arr::get($opts, 'schema');
136-
$operationName = Arr::get($opts, 'operationName');
137-
$rootValue = Arr::get($opts, 'rootValue', null);
133+
$context = $opts['context'] ?? null;
134+
$schemaName = $opts['schema'] ?? null;
135+
$operationName = $opts['operationName'] ?? null;
136+
$rootValue = $opts['rootValue'] ?? null;
138137

139138
$schema = $this->schema($schemaName);
140139

src/GraphQLController.php

+2-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
namespace Rebing\GraphQL;
66

77
use Exception;
8-
use Illuminate\Support\Arr;
98
use Illuminate\Http\Request;
109
use Illuminate\Http\JsonResponse;
1110
use Illuminate\Routing\Controller;
@@ -62,7 +61,7 @@ protected function executeQuery(string $schema, array $input): array
6261
$query = $input['query'];
6362

6463
$paramsKey = config('graphql.params_key', 'variables');
65-
$params = Arr::get($input, $paramsKey);
64+
$params = $input[$paramsKey] ?? null;
6665
if (is_string($params)) {
6766
$params = json_decode($params, true);
6867
}
@@ -73,7 +72,7 @@ protected function executeQuery(string $schema, array $input): array
7372
[
7473
'context' => $this->queryContext($query, $params, $schema),
7574
'schema' => $schema,
76-
'operationName' => Arr::get($input, 'operationName'),
75+
'operationName' => $input['operationName'] ?? null,
7776
]
7877
);
7978
}

src/Support/SelectFields.php

+3-4
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
use Closure;
88
use RuntimeException;
9-
use Illuminate\Support\Arr;
109
use GraphQL\Error\InvariantViolation;
1110
use GraphQL\Type\Definition\UnionType;
1211
use GraphQL\Type\Definition\ResolveInfo;
@@ -163,7 +162,7 @@ protected static function handleFields(
163162
$canSelect = self::validateField($fieldObject, $queryArgs);
164163
if ($canSelect === true) {
165164
// Add a query, if it exists
166-
$customQuery = Arr::get($fieldObject->config, 'query');
165+
$customQuery = $fieldObject->config['query'] ?? null;
167166

168167
// Check if the field is a relation that needs to be requested from the DB
169168
$queryable = self::isQueryable($fieldObject->config);
@@ -177,7 +176,7 @@ protected static function handleFields(
177176
if (isset($parentType->config['model'])) {
178177
// Get the next parent type, so that 'with' queries could be made
179178
// Both keys for the relation are required (e.g 'id' <-> 'user_id')
180-
$relationsKey = Arr::get($fieldObject->config, 'alias', $key);
179+
$relationsKey = $fieldObject->config['alias'] ?? $key;
181180
$relation = call_user_func([app($parentType->config['model']), $relationsKey]);
182181

183182
// Add the foreign key here, if it's a 'belongsTo'/'belongsToMany' relation
@@ -315,7 +314,7 @@ protected static function validateField(FieldDefinition $fieldObject, array $que
315314
*/
316315
private static function isQueryable(array $fieldObject): bool
317316
{
318-
return Arr::get($fieldObject, 'is_relation', true) === true;
317+
return ($fieldObject['is_relation'] ?? true) === true;
319318
}
320319

321320
/**

tests/Support/Objects/UpdateExampleMutation.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
namespace Rebing\GraphQL\Tests\Support\Objects;
66

77
use Closure;
8-
use Illuminate\Support\Arr;
98
use GraphQL\Type\Definition\Type;
109
use Rebing\GraphQL\Support\Mutation;
1110
use GraphQL\Type\Definition\ResolveInfo;
@@ -56,7 +55,7 @@ public function args(): array
5655
public function resolve($root, $args, $context, ResolveInfo $resolveInfo, Closure $getSelectFields): array
5756
{
5857
return [
59-
'test' => Arr::get($args, 'test'),
58+
'test' => $args['test'],
6059
];
6160
}
6261
}

tests/Support/Objects/UpdateExampleMutationWithInputType.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
namespace Rebing\GraphQL\Tests\Support\Objects;
66

7-
use Illuminate\Support\Arr;
87
use GraphQL\Type\Definition\Type;
98
use Rebing\GraphQL\Support\Mutation;
109
use Rebing\GraphQL\Support\Facades\GraphQL;
@@ -66,7 +65,7 @@ public function args(): array
6665
public function resolve($root, $args): array
6766
{
6867
return [
69-
'test' => Arr::get($args, 'test'),
68+
'test' => $args['test'],
7069
];
7170
}
7271
}

0 commit comments

Comments
 (0)