forked from thecodingmachine/graphqlite
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathField.php
More file actions
88 lines (70 loc) · 2.27 KB
/
Copy pathField.php
File metadata and controls
88 lines (70 loc) · 2.27 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
82
83
84
85
86
87
88
<?php
declare(strict_types=1);
namespace TheCodingMachine\GraphQLite\Annotations;
use Attribute;
use function trigger_error;
use const E_USER_DEPRECATED;
#[Attribute(Attribute::TARGET_PROPERTY | Attribute::TARGET_METHOD | Attribute::IS_REPEATABLE)]
class Field extends AbstractGraphQLElement
{
private string|null $prefetchMethod;
/**
* Input/Output type names for which this fields should be applied to.
*
* @var string[]|null
*/
private array|null $for = null;
private string|null $description;
private string|null $inputType;
/**
* @param mixed[] $attributes
* @param string|string[] $for
*/
public function __construct(
array $attributes = [],
string|null $name = null,
string|null $outputType = null,
string|null $prefetchMethod = null,
string|array|null $for = null,
string|null $description = null,
string|null $inputType = null,
) {
parent::__construct($attributes, $name, $outputType);
$this->prefetchMethod = $prefetchMethod ?? $attributes['prefetchMethod'] ?? null;
$this->description = $description ?? $attributes['description'] ?? null;
$this->inputType = $inputType ?? $attributes['inputType'] ?? null;
$forValue = $for ?? $attributes['for'] ?? null;
if (! $forValue) {
return;
}
$this->for = (array) $forValue;
if (! $this->prefetchMethod) {
return;
}
trigger_error(
"Using #[Field(prefetchMethod='" . $this->prefetchMethod . "')] on fields is deprecated in favor " .
"of #[Prefetch('" . $this->prefetchMethod . "')] \$data attribute on the parameter itself.",
E_USER_DEPRECATED,
);
}
/**
* Returns the prefetch method name (the method that will be called to fetch many records at once)
*/
public function getPrefetchMethod(): string|null
{
return $this->prefetchMethod;
}
/** @return string[]|null */
public function getFor(): array|null
{
return $this->for;
}
public function getDescription(): string|null
{
return $this->description;
}
public function getInputType(): string|null
{
return $this->inputType;
}
}