Skip to content

Commit fc10a4d

Browse files
committed
INPUT_FIELD_DEFINITION support.
1 parent 7d5eafd commit fc10a4d

File tree

2 files changed

+42
-5
lines changed

2 files changed

+42
-5
lines changed

src/Utils/SchemaPrinter.php

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -494,8 +494,8 @@ protected static function printInputObject(InputObjectType $type, array $options
494494
{
495495
$fields = array_values($type->getFields());
496496
$fields = array_map(
497-
static function ($f, $i) use ($options): string {
498-
return static::printDescription($options, $f, ' ', ! $i) . ' ' . static::printInputValue($f);
497+
static function (InputObjectField $f, $i) use ($options): string {
498+
return static::printInputObjectField($f, $options, ' ', ! $i);
499499
},
500500
$fields,
501501
array_keys($fields)
@@ -507,6 +507,24 @@ static function ($f, $i) use ($options): string {
507507
static::printBlock($fields);
508508
}
509509

510+
/**
511+
* @param array<string, bool> $options
512+
* @phpstan-param Options $options
513+
*/
514+
protected static function printInputObjectField(InputObjectField $type, array $options, string $indentation = '', bool $firstInBlock = true): string
515+
{
516+
$field = static::printDescription($options, $type, $indentation, $firstInBlock) .
517+
' ' .
518+
static::printInputValue($type) .
519+
static::printTypeDirectives($type, $options, $indentation);
520+
521+
if (!$firstInBlock && mb_strlen($field) > static::LINE_LENGTH) {
522+
$field = "\n".ltrim($field, "\n");
523+
}
524+
525+
return $field;
526+
}
527+
510528
/**
511529
* @param array<string> $items
512530
*/
@@ -518,7 +536,7 @@ protected static function printBlock(array $items): string
518536
}
519537

520538
/**
521-
* @param Type|EnumValueDefinition|EnumType|InterfaceType|FieldDefinition|UnionType|InputObjectType $type
539+
* @param Type|EnumValueDefinition|EnumType|InterfaceType|FieldDefinition|UnionType|InputObjectType|InputObjectField $type
522540
* @param array<string, bool> $options
523541
* @phpstan-param Options $options
524542
*/

tests/Utils/SchemaPrinterTest.php

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1341,7 +1341,12 @@ interface InterfaceB implements InterfaceA @test(value: "{$text}") {
13411341
union UnionB @test(value: "{$text}") = TypeA | TypeB
13421342
13431343
input InputA @test {
1344-
a: Int
1344+
a: Int @test
1345+
b: Int @test(value: "{$text}")
1346+
"{$text}"
1347+
c: Int @test
1348+
"{$text}"
1349+
d: Int @test(value: "{$text}")
13451350
}
13461351
13471352
input InputB @test(value: "{$text}") {
@@ -1376,7 +1381,21 @@ enum EnumB
13761381
}
13771382
13781383
input InputA @test {
1379-
a: Int
1384+
a: Int @test
1385+
1386+
b: Int
1387+
@test(value: "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
1388+
1389+
"""
1390+
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
1391+
"""
1392+
c: Int @test
1393+
1394+
"""
1395+
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
1396+
"""
1397+
d: Int
1398+
@test(value: "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
13801399
}
13811400
13821401
input InputB

0 commit comments

Comments
 (0)