-
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathInputObjectBuilder.php
More file actions
61 lines (49 loc) · 1.27 KB
/
InputObjectBuilder.php
File metadata and controls
61 lines (49 loc) · 1.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
<?php
declare(strict_types=1);
namespace SimPod\GraphQLUtils\Builder;
use GraphQL\Type\Definition\InputObjectType;
/**
* @see InputObjectType
*
* @phpstan-import-type FieldConfig from InputObjectType
* @phpstan-import-type InputObjectConfig from InputObjectType
*/
class InputObjectBuilder extends TypeBuilder
{
/** @var callable():array<FieldConfig>|array<FieldConfig> */
private $fields = [];
private bool $isOneOf = false;
final private function __construct(private string|null $name)
{
}
/** @return static */
public static function create(string $name): self
{
return new static($name);
}
/**
* @param callable():array<FieldConfig>|array<FieldConfig> $fields
*
* @return $this
*/
public function setFields(callable|array $fields): self
{
$this->fields = $fields;
return $this;
}
public function isOneOf(): self
{
$this->isOneOf = true;
return $this;
}
/** @phpstan-return InputObjectConfig */
public function build(): array
{
return [
'name' => $this->name,
'description' => $this->description,
'fields' => $this->fields,
'isOneOf' => $this->isOneOf,
];
}
}