From a579a37f1d98924ae874959297227325ace37063 Mon Sep 17 00:00:00 2001 From: Simon Podlipsky Date: Thu, 24 Jul 2025 12:02:19 +0200 Subject: [PATCH] feat: add support for InputObject @oneOf directive --- src/Builder/InputObjectBuilder.php | 10 ++++++++++ tests/Builder/InputObjectBuilderTest.php | 3 +++ 2 files changed, 13 insertions(+) diff --git a/src/Builder/InputObjectBuilder.php b/src/Builder/InputObjectBuilder.php index 100e27c..02c77cd 100644 --- a/src/Builder/InputObjectBuilder.php +++ b/src/Builder/InputObjectBuilder.php @@ -17,6 +17,8 @@ class InputObjectBuilder extends TypeBuilder /** @var callable():array|array */ private $fields = []; + private bool $isOneOf = false; + final private function __construct(private string|null $name) { } @@ -39,6 +41,13 @@ public function setFields(callable|array $fields): self return $this; } + public function isOneOf(): self + { + $this->isOneOf = true; + + return $this; + } + /** @phpstan-return InputObjectConfig */ public function build(): array { @@ -46,6 +55,7 @@ public function build(): array 'name' => $this->name, 'description' => $this->description, 'fields' => $this->fields, + 'isOneOf' => $this->isOneOf, ]; } } diff --git a/tests/Builder/InputObjectBuilderTest.php b/tests/Builder/InputObjectBuilderTest.php index c549cc3..2b33e3f 100644 --- a/tests/Builder/InputObjectBuilderTest.php +++ b/tests/Builder/InputObjectBuilderTest.php @@ -39,6 +39,7 @@ public function __construct() new InputObjectField(InputFieldBuilder::create('Another', Type::string())->build()), ], ) + ->isOneOf() ->build(); self::assertArrayHasKey('name', $object); @@ -47,5 +48,7 @@ public function __construct() self::assertSame($description, $object['description']); self::assertIsArray($object['fields']); self::assertCount(2, $object['fields']); + self::assertArrayHasKey('isOneOf', $object); + self::assertTrue($object['isOneOf']); } }