Skip to content

Commit 70b0aa3

Browse files
authored
Add support for arg defaultValue (#98)
1 parent 0966d5c commit 70b0aa3

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

src/Builder/FieldBuilder.php

+7-1
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,22 @@ public function setDescription(string $description): self
3737
}
3838

3939
/**
40+
* @param mixed $defaultValue
41+
*
4042
* @return static
4143
*/
42-
public function addArgument(string $name, Type $type, ?string $description = null): self
44+
public function addArgument(string $name, Type $type, ?string $description = null, $defaultValue = null): self
4345
{
4446
$this->parameters['args'][$name] = ['type' => $type];
4547

4648
if ($description !== null) {
4749
$this->parameters['args'][$name]['description'] = $description;
4850
}
4951

52+
if ($defaultValue !== null) {
53+
$this->parameters['args'][$name]['defaultValue'] = $defaultValue;
54+
}
55+
5056
return $this;
5157
}
5258

tests/Builder/FieldBuilderTest.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ static function (): string {
2020
return 'Resolver result';
2121
}
2222
)
23-
->addArgument('arg1', Type::int(), 'Argument Description')
23+
->addArgument('arg1', Type::int(), 'Argument Description', 1)
2424
->build();
2525

2626
self::assertSame('SomeField', $field['name']);
@@ -36,5 +36,6 @@ static function (): string {
3636
self::assertArrayHasKey('arg1', $args);
3737
self::assertSame(Type::int(), $args['arg1']['type']);
3838
self::assertSame('Argument Description', $args['arg1']['description']);
39+
self::assertSame(1, $args['arg1']['defaultValue']);
3940
}
4041
}

0 commit comments

Comments
 (0)