Skip to content

Commit

Permalink
fixed merging of default object values if default value is null
Browse files Browse the repository at this point in the history
  • Loading branch information
peldax committed Sep 14, 2020
1 parent a89c542 commit 404b5b1
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/Argument/ArgumentSet.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ final class ArgumentSet extends \Infinityloop\Utils\ObjectSet implements \Graphp

private array $defaults = [];

public function getDefaults() : array
public function getRawDefaults() : array
{
return $this->defaults;
}
Expand All @@ -30,7 +30,7 @@ protected function getKey(object $object) : string
$defaultValue = $object->getDefaultValue();

if ($defaultValue instanceof \Graphpinator\Resolver\Value\ValidatedValue) {
$this->defaults[$object->getName()] = $defaultValue;
$this->defaults[$object->getName()] = $defaultValue->getRawValue();
}

return $object->getName();
Expand Down
9 changes: 5 additions & 4 deletions src/Type/InputType.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ final public function applyDefaults($value) : \stdClass
throw new \Exception('Composite input type without fields specified.');
}

return self::merge($value, $this->getArguments()->getDefaults());
return self::merge($value, (object) $this->getArguments()->getRawDefaults());
}

final public function getArguments() : \Graphpinator\Argument\ArgumentSet
Expand All @@ -48,12 +48,13 @@ final public function printSchema() : string

abstract protected function getFieldDefinition() : \Graphpinator\Argument\ArgumentSet;

private static function merge(\stdClass $core, iterable $supplement) : \stdClass
private static function merge(\stdClass $core, \stdClass $supplement) : \stdClass
{
foreach ($supplement as $key => $value) {
if (\property_exists($core, $key)) {
if ($core->{$key} instanceof \stdClass) {
$core->{$key} = self::merge($core->{$key}, $supplement[$key]);
if ($core->{$key} instanceof \stdClass &&
$supplement->{$key} instanceof \stdClass) {
$core->{$key} = self::merge($core->{$key}, $supplement->{$key});
}

continue;
Expand Down

0 comments on commit 404b5b1

Please sign in to comment.