1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* This file is part of Railt package. |
5
|
|
|
* |
6
|
|
|
* For the full copyright and license information, please view the LICENSE |
7
|
|
|
* file that was distributed with this source code. |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
declare(strict_types=1); |
11
|
|
|
|
12
|
|
|
namespace Railt\SDL\Backend\Context; |
13
|
|
|
|
14
|
|
|
use GraphQL\Contracts\TypeSystem\Type\ScalarTypeInterface; |
15
|
|
|
use Railt\SDL\Backend\Context; |
16
|
|
|
use Railt\SDL\Frontend\Ast\Definition\Type\ScalarTypeDefinitionNode; |
17
|
|
|
use Railt\TypeSystem\Schema; |
18
|
|
|
use Railt\TypeSystem\Type\ScalarType; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @property-read ScalarTypeDefinitionNode $ast |
22
|
|
|
* @method ScalarTypeDefinitionNode getAst() |
23
|
|
|
*/ |
24
|
|
|
class ScalarTypeDefinitionContext extends NamedTypeContext |
25
|
|
|
{ |
26
|
|
|
/** |
27
|
|
|
* ScalarTypeDefinitionContext constructor. |
28
|
|
|
* |
29
|
|
|
* @param Context $context |
30
|
|
|
* @param Schema $schema |
31
|
|
|
* @param ScalarTypeDefinitionNode $ast |
32
|
|
|
*/ |
33
|
|
|
public function __construct(Context $context, Schema $schema, ScalarTypeDefinitionNode $ast) |
34
|
|
|
{ |
35
|
|
|
parent::__construct($context, $schema, $ast); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @param array $variables |
40
|
|
|
* @return ScalarTypeInterface |
41
|
|
|
* @throws \Throwable |
42
|
|
|
*/ |
43
|
|
|
public function resolve(array $variables = []): ScalarTypeInterface |
44
|
|
|
{ |
45
|
|
|
$ast = $this->precompile($this->ast, $variables); |
46
|
|
|
|
47
|
|
|
$scalar = new ScalarType($ast->name->value, [ |
48
|
|
|
'description' => $this->descriptionOf($ast), |
49
|
|
|
]); |
50
|
|
|
|
51
|
|
|
foreach ($ast->directives as $directive) { |
52
|
|
|
$this->executeDirective($scalar, $directive); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
return $scalar; |
56
|
|
|
} |
57
|
|
|
} |
58
|
|
|
|