Skip to content

Commit b9dccb9

Browse files
committed
feat: register directives via schema config
1 parent 6b8c370 commit b9dccb9

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ CHANGELOG
33

44
[Next release](https://github.com/rebing/graphql-laravel/compare/8.3.0...master)
55
--------------
6+
### Added
7+
- Register directives via schema config [\#946 / sforward](https://github.com/rebing/graphql-laravel/pull/946)
68

79
2022-06-11, 8.3.0
810
-----------------

src/GraphQL.php

+10
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use GraphQL\Error\FormattedError;
1111
use GraphQL\Executor\ExecutionResult;
1212
use GraphQL\Server\OperationParams as BaseOperationParams;
13+
use GraphQL\Type\Definition\Directive;
1314
use GraphQL\Type\Definition\ObjectType;
1415
use GraphQL\Type\Definition\Type;
1516
use GraphQL\Type\Schema;
@@ -363,6 +364,7 @@ public function buildSchemaFromConfig(array $schemaConfig): Schema
363364
$schemaMutation = $schemaConfig['mutation'] ?? [];
364365
$schemaSubscription = $schemaConfig['subscription'] ?? [];
365366
$schemaTypes = $schemaConfig['types'] ?? [];
367+
$schemaDirectives = $schemaConfig['directives'] ?? [];
366368

367369
$this->addTypes($schemaTypes);
368370

@@ -378,10 +380,18 @@ public function buildSchemaFromConfig(array $schemaConfig): Schema
378380
? $this->objectType($schemaSubscription, ['name' => 'Subscription'])
379381
: null;
380382

383+
$directives = Directive::getInternalDirectives();
384+
385+
foreach ($schemaDirectives as $class) {
386+
$directive = $this->app->make($class);
387+
$directives[$directive->name] = $directive;
388+
}
389+
381390
return new Schema([
382391
'query' => $query,
383392
'mutation' => $mutation,
384393
'subscription' => $subscription,
394+
'directives' => $directives,
385395
'types' => function () {
386396
$types = [];
387397

0 commit comments

Comments
 (0)