1
|
|
|
<?php declare(strict_types=1); |
2
|
|
|
|
3
|
|
|
namespace Modelarium\Laravel\Directives; |
4
|
|
|
|
5
|
|
|
use Modelarium\Exception\DirectiveException; |
6
|
|
|
use Modelarium\Laravel\Targets\MigrationGenerator; |
7
|
|
|
use Modelarium\Laravel\Targets\Interfaces\MigrationDirectiveInterface; |
8
|
|
|
use Modelarium\Laravel\Targets\MigrationCodeFragment; |
9
|
|
|
use Modelarium\Parser; |
10
|
|
|
|
11
|
|
|
class MigrationDefaultValueDirective implements MigrationDirectiveInterface |
12
|
|
|
{ |
13
|
|
|
public static function processMigrationTypeDirective( |
14
|
|
|
MigrationGenerator $generator, |
15
|
|
|
\GraphQL\Language\AST\DirectiveNode $directive |
16
|
|
|
): void { |
17
|
|
|
throw new DirectiveException("@defaultValue not allowed on types."); |
18
|
|
|
} |
19
|
|
|
|
20
|
|
|
public static function processMigrationFieldDirective( |
21
|
|
|
MigrationGenerator $generator, |
22
|
|
|
\GraphQL\Type\Definition\FieldDefinition $field, |
23
|
|
|
\GraphQL\Language\AST\DirectiveNode $directive, |
24
|
|
|
MigrationCodeFragment $code |
25
|
|
|
): void { |
26
|
|
|
$x = Parser::getDirectiveArgumentByName($directive, 'value'); |
27
|
|
|
$code->appendBase('->default(' . $x . ')'); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
public static function processMigrationRelationshipDirective( |
31
|
|
|
MigrationGenerator $generator, |
32
|
|
|
\GraphQL\Type\Definition\FieldDefinition $field, |
33
|
|
|
\GraphQL\Language\AST\DirectiveNode $directive, |
34
|
|
|
MigrationCodeFragment $code |
35
|
|
|
): void { |
36
|
|
|
throw new DirectiveException("@defaultValue not allowed on relationships."); |
37
|
|
|
} |
38
|
|
|
} |
39
|
|
|
|