From 46b38d5ca6dccbade10f08930d169baf851352f3 Mon Sep 17 00:00:00 2001
From: Omar Lopesino <omar.lopesino@metadrop.net>
Date: Tue, 18 Feb 2025 16:31:12 +0100
Subject: [PATCH 1/2] Issue #3507476: Allow Lists of Strings in GraphQL views

---
 .../src/Plugin/GraphQLCompose/SchemaType/View.php           | 3 +++
 .../src/Plugin/views/row/GraphQLFieldRow.php                | 6 +++++-
 2 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/modules/graphql_compose_views/src/Plugin/GraphQLCompose/SchemaType/View.php b/modules/graphql_compose_views/src/Plugin/GraphQLCompose/SchemaType/View.php
index 7c232d37..cdf0afab 100644
--- a/modules/graphql_compose_views/src/Plugin/GraphQLCompose/SchemaType/View.php
+++ b/modules/graphql_compose_views/src/Plugin/GraphQLCompose/SchemaType/View.php
@@ -421,6 +421,9 @@ class View extends GraphQLComposeSchemaTypeBase {
 
         $type_fields[$field_alias] = $custom_scalar;
       }
+      elseif ($field_type == 'List String') {
+        $type_fields[$field_alias] = Type::listOf(Type::string());
+      }
       else {
         $type_fields[$field_alias] = call_user_func([
           Type::class,
diff --git a/modules/graphql_compose_views/src/Plugin/views/row/GraphQLFieldRow.php b/modules/graphql_compose_views/src/Plugin/views/row/GraphQLFieldRow.php
index 3cae9e15..1eb15e6f 100644
--- a/modules/graphql_compose_views/src/Plugin/views/row/GraphQLFieldRow.php
+++ b/modules/graphql_compose_views/src/Plugin/views/row/GraphQLFieldRow.php
@@ -126,6 +126,7 @@ class GraphQLFieldRow extends RowPluginBase {
           '#type' => 'select',
           '#options' => [
             'String' => $this->t('String'),
+            'List String' => $this->t('List (String)'),
             'Int' => $this->t('Int'),
             'Float' => $this->t('Float'),
             'Boolean' => $this->t('Boolean'),
@@ -179,7 +180,6 @@ class GraphQLFieldRow extends RowPluginBase {
     $output = [];
 
     foreach ($this->view->field as $id => $field) {
-
       // Omit excluded fields from the rendered output.
       if (!empty($field->options['exclude'])) {
         continue;
@@ -235,6 +235,10 @@ class GraphQLFieldRow extends RowPluginBase {
         $value = (float) filter_var($value, FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION);
       }
 
+      if ($this->getFieldType($id) == 'List String') {
+        $value = array_map('trim', explode($field->options['separator'], $value));
+      }
+
       $output[$this->getFieldKeyAlias($id)] = $value;
     }
 
-- 
GitLab


From d8374274c314d979e09f0eef3b74967cfdc0596b Mon Sep 17 00:00:00 2001
From: Omar Lopesino <omar.lopesino@metadrop.net>
Date: Wed, 19 Feb 2025 16:29:48 +0100
Subject: [PATCH 2/2] Issue #3507476: Array filter

---
 .../src/Plugin/views/row/GraphQLFieldRow.php                    | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/modules/graphql_compose_views/src/Plugin/views/row/GraphQLFieldRow.php b/modules/graphql_compose_views/src/Plugin/views/row/GraphQLFieldRow.php
index 1eb15e6f..2666c3a5 100644
--- a/modules/graphql_compose_views/src/Plugin/views/row/GraphQLFieldRow.php
+++ b/modules/graphql_compose_views/src/Plugin/views/row/GraphQLFieldRow.php
@@ -236,7 +236,7 @@ class GraphQLFieldRow extends RowPluginBase {
       }
 
       if ($this->getFieldType($id) == 'List String') {
-        $value = array_map('trim', explode($field->options['separator'], $value));
+        $value = array_map('trim', array_filter(explode($field->options['separator'], $value)));
       }
 
       $output[$this->getFieldKeyAlias($id)] = $value;
-- 
GitLab