Skip to content

Commit

Permalink
Fix: Block fields in object bricks are always output as null even tho…
Browse files Browse the repository at this point in the history
…ugh they are filled (#734)

* Fix: Block fields in object bricks are always output as null even though they are filled

* Fix PhpStan

* Fix: language arg is ignored
  • Loading branch information
blankse committed May 5, 2023
1 parent f1e3323 commit 55683f7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
19 changes: 14 additions & 5 deletions src/GraphQL/DataObjectQueryFieldConfigGenerator/Block.php
Expand Up @@ -75,6 +75,9 @@ public function getResolver($attribute, $fieldDefinition, $class)
$isBrick = false;
$attributeParts = explode('~', $attribute);
$fieldname = $fieldDefinition->getName();
$brickDescriptor = null;
$brickType = null;
$brickKey = null;

if (count($attributeParts) > 1) {
$id = $value['id'];
Expand All @@ -85,9 +88,13 @@ public function getResolver($attribute, $fieldDefinition, $class)
}

$context = ['object' => $object];
$brickDescriptor = null;

$brickType = $attributeParts[0];
if (strpos($brickType, '?') !== false) {
$brickDescriptor = substr($brickType, 1);
$brickDescriptor = json_decode($brickDescriptor, true);
$brickType = $brickDescriptor['containerKey'];
}
$brickKey = $attributeParts[1];

$key = Service::getFieldForBrickType($object->getclass(), $brickType);
Expand Down Expand Up @@ -152,8 +159,9 @@ public function getResolver($attribute, $fieldDefinition, $class)
$blockDescriptor['__fcType'] = $originalValue['__fcType'];
$blockDescriptor['__itemIdx'] = $originalValue['__itemIdx'];
} elseif ($isBrick) {
$blockDescriptor['__brickType'] = $attributeParts[0];
$blockDescriptor['__brickKey'] = $attributeParts[1];
$blockDescriptor['__brickDescriptor'] = $brickDescriptor;
$blockDescriptor['__brickType'] = $brickType;
$blockDescriptor['__brickKey'] = $brickKey;
}

$result[$blockIndex][$localizedDef->getName()] = $blockDescriptor;
Expand All @@ -174,8 +182,9 @@ public function getResolver($attribute, $fieldDefinition, $class)
$blockDescriptor['__fcType'] = $originalValue['__fcType'];
$blockDescriptor['__itemIdx'] = $originalValue['__itemIdx'];
} elseif ($isBrick) {
$blockDescriptor['__brickType'] = $attributeParts[0];
$blockDescriptor['__brickKey'] = $attributeParts[1];
$blockDescriptor['__brickDescriptor'] = $brickDescriptor;
$blockDescriptor['__brickType'] = $brickType;
$blockDescriptor['__brickKey'] = $brickKey;
}

$result[$blockIndex][$key] = $blockDescriptor;
Expand Down
4 changes: 2 additions & 2 deletions src/GraphQL/Service.php
Expand Up @@ -986,7 +986,7 @@ public static function resolveValue(BaseDescriptor $descriptor, Data $fieldDefin
}
} elseif (isset($descriptorData['__brickType']) && $descriptorData['__brickType']) {
$context = ['object' => $object];
$brickDescriptor = null;
$brickDescriptor = $descriptorData['__brickDescriptor'] ?? null;

$brickType = $descriptorData['__brickType'];
$brickKey = $descriptorData['__brickKey'];
Expand All @@ -1008,7 +1008,7 @@ public static function resolveValue(BaseDescriptor $descriptor, Data $fieldDefin
}

if (!empty($key)) {
$blockData = self::getValueForObject($object, $key, $brickType, $brickKey, $def, $context, $brickDescriptor, $args);
$blockData = self::getValueForObject($object, $key, $brickType, $brickKey, $def, $context, $brickDescriptor, $descriptorData['args'] ?? []);
}
} else {
$blockGetter = 'get'.ucfirst($descriptorData['__blockName']);
Expand Down

0 comments on commit 55683f7

Please sign in to comment.