Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/Builder/InputObjectBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ class InputObjectBuilder extends TypeBuilder
/** @var callable():array<FieldConfig>|array<FieldConfig> */
private $fields = [];

private bool $isOneOf = false;

final private function __construct(private string|null $name)
{
}
Expand All @@ -39,13 +41,21 @@ 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
{
return [
'name' => $this->name,
'description' => $this->description,
'fields' => $this->fields,
'isOneOf' => $this->isOneOf,
];
}
}
3 changes: 3 additions & 0 deletions tests/Builder/InputObjectBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public function __construct()
new InputObjectField(InputFieldBuilder::create('Another', Type::string())->build()),
],
)
->isOneOf()
->build();

self::assertArrayHasKey('name', $object);
Expand All @@ -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']);
}
}
Loading