Skip to content

Commit d75e93f

Browse files
authored
Merge pull request #14 from roippi/master
allow default typeservice to resolve public fields on objects
2 parents c79eb70 + 5241e24 commit d75e93f

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

Diff for: Tests/Library/Utilities/TypeUtilitiesTest.php

+8
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Youshido\GraphQL\Type\TypeService;
1515
use Youshido\Tests\DataProvider\TestInterfaceType;
1616
use Youshido\Tests\DataProvider\TestObjectType;
17+
use Youshido\Tests\Library\Type\ObjectTypeTest;
1718

1819
class TypeUtilitiesTest extends \PHPUnit_Framework_TestCase
1920
{
@@ -55,4 +56,11 @@ public function testIsAbstractType()
5556
$this->assertFalse(TypeService::isAbstractType(new StringType()));
5657
$this->assertFalse(TypeService::isAbstractType('invalid type'));
5758
}
59+
60+
public function testGetPropertyValue() {
61+
$arrayData = (new TestObjectType())->getData();
62+
63+
$this->assertEquals('John', TypeService::getPropertyValue($arrayData, 'name'));
64+
$this->assertEquals('John', TypeService::getPropertyValue((object) $arrayData, 'name'));
65+
}
5866
}

Diff for: src/Type/TypeService.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ public static function getPropertyValue($data, $path)
127127
$getter = 'get' . self::classify($path);
128128
}
129129

130-
return is_callable([$data, $getter]) ? $data->$getter() : null;
130+
return is_callable([$data, $getter]) ? $data->$getter() : (isset($data->$path) ? $data->$path : null);
131131
} elseif (is_array($data)) {
132132
return array_key_exists($path, $data) ? $data[$path] : null;
133133
}

0 commit comments

Comments
 (0)