Skip to content

Commit d524cb9

Browse files
committed
no message
1 parent eae0c0c commit d524cb9

3 files changed

Lines changed: 48 additions & 1 deletion

File tree

src/Utils/ASTDefinitionBuilder.php

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -536,16 +536,40 @@ private function makeScalarDef(ScalarTypeDefinitionNode $def): CustomScalarType
536536
]);
537537
}
538538

539-
/** @throws InvariantViolation */
539+
/**
540+
* @throws \Exception
541+
* @throws \ReflectionException
542+
* @throws InvariantViolation
543+
*/
540544
private function makeInputObjectDef(InputObjectTypeDefinitionNode $def): InputObjectType
541545
{
542546
$name = $def->name->value;
543547
/** @var array<InputObjectTypeExtensionNode> $extensionASTNodes (proven by schema validation) */
544548
$extensionASTNodes = $this->typeExtensionsMap[$name] ?? [];
545549

550+
// Check for @oneOf directive in the definition node
551+
$isOneOf = Values::getDirectiveValues(
552+
Directive::oneOfDirective(),
553+
$def
554+
) !== null;
555+
556+
// Check for @oneOf directive in extension nodes
557+
if (! $isOneOf) {
558+
foreach ($extensionASTNodes as $extensionNode) {
559+
if (Values::getDirectiveValues(
560+
Directive::oneOfDirective(),
561+
$extensionNode
562+
) !== null) {
563+
$isOneOf = true;
564+
break;
565+
}
566+
}
567+
}
568+
546569
return new InputObjectType([
547570
'name' => $name,
548571
'description' => $def->description->value ?? null,
572+
'isOneOf' => $isOneOf,
549573
'fields' => fn (): array => $this->makeInputFields([$def, ...$extensionASTNodes]),
550574
'astNode' => $def,
551575
'extensionASTNodes' => $extensionASTNodes,

src/Utils/SchemaPrinter.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -563,6 +563,7 @@ protected static function printInputObject(InputObjectType $type, array $options
563563

564564
return static::printDescription($options, $type)
565565
. "input {$type->name}"
566+
. ($type->isOneOf() ? ' @oneOf' : '')
566567
. static::printBlock($fields);
567568
}
568569

tests/Utils/SchemaPrinterTest.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -752,6 +752,28 @@ public function testInputType(): void
752752
);
753753
}
754754

755+
/** @see it('Print Input Type with @oneOf directive') */
756+
public function testInputTypeWithOneOfDirective(): void
757+
{
758+
$inputType = new InputObjectType([
759+
'name' => 'InputType',
760+
'isOneOf' => true,
761+
'fields' => ['int' => ['type' => Type::int()]],
762+
]);
763+
764+
$schema = new Schema(['types' => [$inputType]]);
765+
766+
self::assertPrintedSchemaEquals(
767+
<<<'GRAPHQL'
768+
input InputType @oneOf {
769+
int: Int
770+
}
771+
772+
GRAPHQL,
773+
$schema
774+
);
775+
}
776+
755777
/** @see it('Custom Scalar') */
756778
public function testCustomScalar(): void
757779
{

0 commit comments

Comments
 (0)