Skip to content

Commit da8b153

Browse files
committed
test: add test for registration of directives via buildSchemaFromConfig
1 parent b977ebf commit da8b153

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
declare(strict_types = 1);
4+
namespace Rebing\GraphQL\Tests\Support\Directives;
5+
6+
use GraphQL\Language\DirectiveLocation;
7+
use GraphQL\Type\Definition\Directive;
8+
use GraphQL\Type\Definition\FieldArgument;
9+
use GraphQL\Type\Definition\Type;
10+
11+
class ExampleDirective extends Directive
12+
{
13+
public function __construct()
14+
{
15+
parent::__construct([
16+
'name' => 'exampleDirective',
17+
'description' => 'This is an example directive',
18+
'locations' => [
19+
// See DirectiveLocation constants for all available locations
20+
DirectiveLocation::QUERY,
21+
],
22+
'args' => [
23+
new FieldArgument([
24+
'name' => 'first',
25+
'description' => 'Description of this argument',
26+
'type' => Type::string(),
27+
]),
28+
],
29+
]);
30+
}
31+
}

tests/Unit/GraphQLTest.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Rebing\GraphQL\Exception\SchemaNotFound;
1616
use Rebing\GraphQL\Exception\TypeNotFound;
1717
use Rebing\GraphQL\Support\Facades\GraphQL;
18+
use Rebing\GraphQL\Tests\Support\Directives\ExampleDirective;
1819
use Rebing\GraphQL\Tests\Support\Objects\CustomExampleType;
1920
use Rebing\GraphQL\Tests\Support\Objects\ExamplesQuery;
2021
use Rebing\GraphQL\Tests\Support\Objects\ExampleType;
@@ -454,6 +455,25 @@ public function testAddSchemaObjectAndExecuteQueryWithRootValue(): void
454455
self::assertSame($expectedResult, $result);
455456
}
456457

458+
public function testBuildSchemaWithDirectives(): void
459+
{
460+
$schema = GraphQL::buildSchemaFromConfig([
461+
'query' => [
462+
'examplesCustom' => ExamplesQuery::class,
463+
],
464+
'directives' => [
465+
ExampleDirective::class,
466+
],
467+
]);
468+
469+
self::assertSame([
470+
'include',
471+
'skip',
472+
'deprecated',
473+
'exampleDirective',
474+
], array_keys($schema->getDirectives()));
475+
}
476+
457477
public function testIsMacroable(): void
458478
{
459479
self::assertContains(Macroable::class, class_uses_recursive(GraphQL::getFacadeRoot()));

0 commit comments

Comments
 (0)