forked from thecodingmachine/graphqlite
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFactory.php
More file actions
66 lines (57 loc) · 2.06 KB
/
Factory.php
File metadata and controls
66 lines (57 loc) · 2.06 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
<?php
declare(strict_types=1);
namespace TheCodingMachine\GraphQLite\Annotations;
use Attribute;
use TheCodingMachine\GraphQLite\GraphQLRuntimeException;
/**
* Factories are methods used to declare GraphQL input types.
*/
#[Attribute(Attribute::TARGET_METHOD)]
class Factory
{
private string|null $name;
private bool $default;
private string|null $description;
/** @param mixed[] $attributes */
public function __construct(
array $attributes = [],
string|null $name = null,
bool|null $default = null,
string|null $description = null,
) {
$this->name = $name ?? $attributes['name'] ?? null;
// This IS the default if no name is set and no "default" attribute is passed.
$this->default = $default ?? $attributes['default'] ?? ! isset($attributes['name']);
$this->description = $description ?? $attributes['description'] ?? null;
if ($this->name === null && $this->default === false) {
throw new GraphQLRuntimeException('A #[Factory] that has "default=false" attribute must be given a name (i.e. add a name="FooBarInput" attribute).');
}
}
/**
* Returns the name of the GraphQL input type.
* If not specified, the name of the method should be used instead.
*/
public function getName(): string|null
{
return $this->name;
}
/**
* Returns true if this factory should map the return type of the factory by default.
*/
public function isDefault(): bool
{
return $this->default;
}
/**
* Returns the explicit description for the GraphQL input type produced by this factory,
* or null if none was provided.
*
* A null return means "no explicit description" and the schema builder may fall back to the
* docblock summary (if docblock descriptions are enabled on the SchemaFactory). An explicit
* empty string blocks the docblock fallback and produces an empty description.
*/
public function getDescription(): string|null
{
return $this->description;
}
}