magento / magento2-pwa

Other
15 stars 13 forks source link

Type error thrown by `attributesMetadata` query #12

Open aligent-lturner opened 1 year ago

aligent-lturner commented 1 year ago

The attributesMetadata query can result in a type error being thrown:

[2023-05-18T06:39:53.610798+00:00] report.ERROR: Magento\PageBuilderPwa\Plugin\UiInputTypePageBuilder::afterGetAttributeMetadata(): Argument #2 ($result) must be of type array, null given, called in /app/vendor/magento/framework/Interception/Interceptor.php on line 146

GraphQL (2:3)
1: query {
2:   attributesMetadata(
     ^
3:     entityType: PRODUCT,
 {"exception":"[object] (GraphQL\\Error\\Error(code: 0): Magento\\PageBuilderPwa\\Plugin\\UiInputTypePageBuilder::afterGetAttributeMetadata(): Argument #2 ($result) must be of type array, null given, called in /app/vendor/magento/framework/Interception/Interceptor.php on line 146 at /app/vendor/webonyx/graphql-php/src/Error/Error.php:153)
[previous exception] [object] (TypeError(code: 0): Magento\\PageBuilderPwa\\Plugin\\UiInputTypePageBuilder::afterGetAttributeMetadata(): Argument #2 ($result) must be of type array, null given, called in /app/vendor/magento/framework/Interception/Interceptor.php on line 146 at /app/vendor/magento/module-page-builder-pwa/Plugin/UiInputTypePageBuilder.php:43)"} []
[2023-05-18T06:39:53.610798+00:00] report.ERROR: Magento\PageBuilderPwa\Plugin\UiInputTypePageBuilder::afterGetAttributeMetadata(): Argument #2 ($result) must be of type array, null given, called in /app/vendor/magento/framework/Interception/Interceptor.php on line 146

The function afterGetAttributeMetadata has the $result parameter typed as array - https://github.com/magento/magento2-pwa/blob/ed1a13f8ba0a303e08d594ab01b555243c245529/PageBuilderPwa/Plugin/UiInputTypePageBuilder.php#L43-L47

However, the function it is plugging into can return void (i.e. null) - https://github.com/magento/magento2-pwa/blob/ed1a13f8ba0a303e08d594ab01b555243c245529/EavGraphQlAux/Model/Resolver/DataProvider/AttributeMetadata.php#L60-L68

The plugin should handle this case by changing the input parameter type to ?array, and handling the case where it is null.