Skip to content

Commit

Permalink
Add support for arg defaultValue (#98)
Browse files Browse the repository at this point in the history
  • Loading branch information
simPod authored Sep 8, 2021
1 parent 0966d5c commit 70b0aa3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
8 changes: 7 additions & 1 deletion src/Builder/FieldBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,22 @@ public function setDescription(string $description): self
}

/**
* @param mixed $defaultValue
*
* @return static
*/
public function addArgument(string $name, Type $type, ?string $description = null): self
public function addArgument(string $name, Type $type, ?string $description = null, $defaultValue = null): self
{
$this->parameters['args'][$name] = ['type' => $type];

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

if ($defaultValue !== null) {
$this->parameters['args'][$name]['defaultValue'] = $defaultValue;
}

return $this;
}

Expand Down
3 changes: 2 additions & 1 deletion tests/Builder/FieldBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ static function (): string {
return 'Resolver result';
}
)
->addArgument('arg1', Type::int(), 'Argument Description')
->addArgument('arg1', Type::int(), 'Argument Description', 1)
->build();

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

0 comments on commit 70b0aa3

Please sign in to comment.