-
-
Notifications
You must be signed in to change notification settings - Fork 575
Expand file tree
/
Copy pathScalarType.php
More file actions
81 lines (69 loc) · 2.11 KB
/
Copy pathScalarType.php
File metadata and controls
81 lines (69 loc) · 2.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
<?php declare(strict_types=1);
namespace GraphQL\Type\Definition;
use GraphQL\Error\InvariantViolation;
use GraphQL\Language\AST\ScalarTypeDefinitionNode;
use GraphQL\Language\AST\ScalarTypeExtensionNode;
use GraphQL\Utils\Utils;
/**
* Scalar Type Definition.
*
* The leaf values of any request and input values to arguments are
* Scalars (or Enums) and are defined with a name and a series of coercion
* functions used to ensure validity.
*
* Example:
*
* class OddType extends ScalarType
* {
* public $name = 'Odd',
* public function serialize($value)
* {
* return $value % 2 === 1 ? $value : null;
* }
* }
*
* @phpstan-type ScalarConfig array{
* name?: string|null,
* description?: string|null,
* specifiedByURL?: string|null,
* astNode?: ScalarTypeDefinitionNode|null,
* extensionASTNodes?: array<ScalarTypeExtensionNode>|null
* }
*/
abstract class ScalarType extends Type implements OutputType, InputType, LeafType, NullableType, NamedType
{
use NamedTypeImplementation;
public ?ScalarTypeDefinitionNode $astNode;
public ?string $specifiedByURL;
/** @var array<ScalarTypeExtensionNode> */
public array $extensionASTNodes;
/** @phpstan-var ScalarConfig */
public array $config;
/**
* @phpstan-param ScalarConfig $config
*
* @throws InvariantViolation
*/
public function __construct(array $config = [])
{
$this->name = $config['name'] ?? $this->inferName();
$this->description = $config['description'] ?? $this->description ?? null;
$this->specifiedByURL = $config['specifiedByURL'] ?? null;
$this->astNode = $config['astNode'] ?? null;
$this->extensionASTNodes = $config['extensionASTNodes'] ?? [];
$this->config = $config;
}
public function assertValid(): void
{
Utils::assertValidName($this->name);
}
public function astNode(): ?ScalarTypeDefinitionNode
{
return $this->astNode;
}
/** @return array<ScalarTypeExtensionNode> */
public function extensionASTNodes(): array
{
return $this->extensionASTNodes;
}
}