Skip to content

Commit 723f04c

Browse files
authored
feat: add support for InputObject @OneOf directive (#180)
1 parent 96fdb72 commit 723f04c

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

src/Builder/InputObjectBuilder.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ class InputObjectBuilder extends TypeBuilder
1717
/** @var callable():array<FieldConfig>|array<FieldConfig> */
1818
private $fields = [];
1919

20+
private bool $isOneOf = false;
21+
2022
final private function __construct(private string|null $name)
2123
{
2224
}
@@ -39,13 +41,21 @@ public function setFields(callable|array $fields): self
3941
return $this;
4042
}
4143

44+
public function isOneOf(): self
45+
{
46+
$this->isOneOf = true;
47+
48+
return $this;
49+
}
50+
4251
/** @phpstan-return InputObjectConfig */
4352
public function build(): array
4453
{
4554
return [
4655
'name' => $this->name,
4756
'description' => $this->description,
4857
'fields' => $this->fields,
58+
'isOneOf' => $this->isOneOf,
4959
];
5060
}
5161
}

tests/Builder/InputObjectBuilderTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ public function __construct()
3939
new InputObjectField(InputFieldBuilder::create('Another', Type::string())->build()),
4040
],
4141
)
42+
->isOneOf()
4243
->build();
4344

4445
self::assertArrayHasKey('name', $object);
@@ -47,5 +48,7 @@ public function __construct()
4748
self::assertSame($description, $object['description']);
4849
self::assertIsArray($object['fields']);
4950
self::assertCount(2, $object['fields']);
51+
self::assertArrayHasKey('isOneOf', $object);
52+
self::assertTrue($object['isOneOf']);
5053
}
5154
}

0 commit comments

Comments
 (0)