1
|
|
|
<?php declare(strict_types=1); |
2
|
|
|
|
3
|
|
|
namespace Modelarium\Laravel\Directives; |
4
|
|
|
|
5
|
|
|
use GraphQL\Language\AST\DirectiveNode; |
6
|
|
|
use Modelarium\Laravel\Targets\ModelGenerator; |
7
|
|
|
use Modelarium\Laravel\Targets\Interfaces\ModelDirectiveInterface; |
8
|
|
|
|
9
|
|
|
class CastsDirective implements ModelDirectiveInterface |
10
|
|
|
{ |
11
|
|
|
public static function processModelTypeDirective( |
12
|
|
|
ModelGenerator $generator, |
13
|
|
|
\GraphQL\Language\AST\DirectiveNode $directive |
14
|
|
|
): void { |
15
|
|
|
} |
16
|
|
|
|
17
|
|
|
public static function processModelFieldDirective( |
18
|
|
|
ModelGenerator $generator, |
19
|
|
|
\GraphQL\Type\Definition\FieldDefinition $field, |
20
|
|
|
\Formularium\Field $fieldFormularium, |
21
|
|
|
\GraphQL\Language\AST\DirectiveNode $directive |
22
|
|
|
): void { |
23
|
|
|
$fieldName = $field->name; |
24
|
|
|
foreach ($directive->arguments as $arg) { |
25
|
|
|
/** |
26
|
|
|
* @var \GraphQL\Language\AST\ArgumentNode $arg |
27
|
|
|
*/ |
28
|
|
|
/** @phpstan-ignore-next-line */ |
29
|
|
|
$value = $arg->value->value; |
30
|
|
|
|
31
|
|
|
switch ($arg->name->value) { |
32
|
|
|
case 'type': |
33
|
|
|
$generator->casts[$fieldName] = $value; |
34
|
|
|
} |
35
|
|
|
} |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
public static function processModelRelationshipDirective( |
39
|
|
|
ModelGenerator $generator, |
40
|
|
|
\GraphQL\Type\Definition\FieldDefinition $field, |
41
|
|
|
\GraphQL\Language\AST\DirectiveNode $directive, |
42
|
|
|
\Formularium\Datatype $datatype = null |
43
|
|
|
): ?\Formularium\Datatype { |
44
|
|
|
return null; |
45
|
|
|
} |
46
|
|
|
} |
47
|
|
|
|