Skip to content

Commit

Permalink
Add inheritance check for field mapping
Browse files Browse the repository at this point in the history
  • Loading branch information
Aaron Carlino committed Apr 7, 2021
1 parent dd4a2aa commit fe33277
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/Schema/DataObject/Resolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,19 @@ class Resolver
*/
public static function resolve($obj, $args = [], $context = [], ?ResolveInfo $info = null)
{

$fieldName = $info->fieldName;
$context = SchemaConfigProvider::get($context);
$fieldName = $context->mapFieldByClassName(get_class($obj), $fieldName);
$result = $fieldName ? FieldAccessor::singleton()->accessField($obj, $fieldName[1]) : null;
$class = get_class($obj);
$resolvedField = null;
while(!$resolvedField && $class !== DataObject::class) {
$resolvedField = $context->mapFieldByClassName($class, $fieldName);
$class = get_parent_class($class);
}

if (!$resolvedField) {
return null;
}
$result = FieldAccessor::singleton()->accessField($obj, $resolvedField[1]);
if ($result instanceof DBField) {
return $result->getValue();
}
Expand Down

0 comments on commit fe33277

Please sign in to comment.