Resolve MapItem type fields

Created on 5 January 2024, 12 months ago

Problem/Motivation

Currently FieldTypeMapItem fields in graphql are resolved to NULL. It would be good if MapItem fields can also be resolved generically.

Steps to reproduce

1. Create a computed field(or a normal map field?) of map type.
2. Query field and notice that it is null. (Also its raw field do not have a value key).

Proposed resolution

This can be fixed by adding below code to CoreComposableResolver::extractFieldValue():

--- a/src/CoreComposableResolver.php
+++ b/src/CoreComposableResolver.php
@@ -349,6 +349,9 @@ class CoreComposableResolver {
       if ($pluginId === 'field_item:telephone') {
         return $item->value;
       }
+      elseif ($pluginId === 'field_item:map') {
+        return $item->getValue();
+      }
     }

     return $item;

Remaining tasks

Add resolver to raw_field of map type ('value' key). I assume there is a generic logic to achieve this and just need help from someone more familiar with module code.

One way to achieve this is by adding a custom resolver by extending FieldItemTypeMap type:

extend type FieldItemTypeMap {
  value: MapData
}
addFieldResolver('FieldItemTypeMap', 'value',
      $builder->callback(function ($item) {
        $values = $item->getValue();
        return $values;
      })
    );
?>>
🐛 Bug report
Status

Active

Version

1.0

Component

Code

Created by

🇮🇳India sumit_saini

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024