没有不值得去解决的问题,也没有不值得去学习的技术!

在 Laravel 6、Lighthouse 中,debugMessage”: “Expected a value of type \”String\” but received: [\”en-US\”,\”zh-CN\”,\”sp-ES\”,\”fr-FR\”,\”de-DE\”,\”pt-PT\”,\”it-IT\”]

在 Laravel 6、Lighthouse 中,debugMessage": "Expected a value of type \"String\" but received: [\"en-US\",\"zh-CN\",\"sp-ES\",\"fr-FR\",\"de-DE\",\"pt-PT\",\"it-IT\"]
1、在 Laravel 6、Lighthouse 中,debugMessage”: “Expected a value of type \”String\” but received: [\”en-US\”,\”zh-CN\”,\”sp-ES\”,\”fr-FR\”,\”de-DE\”,\”pt-PT\”,\”it-IT\”]。如图1
在 Laravel 6、Lighthouse 中,debugMessage": "Expected a value of type \"String\" but received: [\"en-US\",\"zh-CN\",\"sp-ES\",\"fr-FR\",\"de-DE\",\"pt-PT\",\"it-IT\"]
图1


{
  "errors": [
    {
      "debugMessage": "Expected a value of type \"String\" but received: [\"en-US\",\"zh-CN\",\"sp-ES\",\"fr-FR\",\"de-DE\",\"pt-PT\",\"it-IT\"]",
      "message": "Internal server error",
      "extensions": {
        "category": "internal"
      },
      "locations": [
        {
          "line": 34,
          "column": 9
        }
      ],
      "path": [
        "onlineStoreTheme",
        "current",
        "settings",
        31,
        "value"
      ],
      "trace": ...
    },
    {
      "debugMessage": "Cannot return null for non-nullable field \"ThemePreset.sections\".",
      "message": "Internal server error",
      "extensions": {
        "category": "internal"
      },
      "locations": [
        {
          "line": 139,
          "column": 3
        }
      ],
      "path": [
        "onlineStoreTheme",
        "current",
        "sections",
        0
      ],
      "trace": ...
    }
  ],
  "data": {
    "onlineStoreTheme": null
  }
}


2、打印 dd($resolvedData[‘current’][‘settings’][31]); ,结果如下。第 31 个元素的 value ,为数组格式。如图2
打印 dd($resolvedData['current']['settings'][31]); ,结果如下。第 31 个元素的 value ,为数组格式
图2


Illuminate\Support\Collection {#11225
  #items: array:33 [
    "available_languages" => array:4 [
      "id" => Modules\ThemeStore\Resolver\Id {#11223
        #prefixes: array:3 [
          0 => "theme"
          1 => "current"
          2 => "available_languages"
        ]
      }
      "settingId" => "available_languages"
      "value" => array:7 [
        0 => "en-US"
        1 => "zh-CN"
        2 => "sp-ES"
        3 => "fr-FR"
        4 => "de-DE"
        5 => "pt-PT"
        6 => "it-IT"
      ]
      "type" => "select"
    ]
  ]
}


3、编辑解析器方法,var_dump($value);,打印出值的列表


int(0)
int(0)
string(7) "#ff0000"
string(7) "#000000"
string(7) "#990000"
string(7) "#212529"
string(7) "#999999"
string(7) "#c90d0d"
string(40) "linear-gradient(90deg, #c90d0d, #c90d0d)"
string(7) "#c90d0d"
string(40) "linear-gradient(90deg, #c90d0d, #c90d0d)"
string(7) "#ffffff"
string(40) "linear-gradient(90deg, #ffffff, #ffffff)"
string(7) "#f9f1e6"
string(40) "linear-gradient(90deg, #f9f1e6, #f9f1e6)"
string(9) "Open Sans"
string(9) "Open Sans"
string(9) "Open Sans"
NULL
NULL
NULL
NULL
NULL
NULL
NULL
NULL
NULL
NULL
bool(false)
string(5) "en-US"
bool(false)
array(7) {
  [0]=>
  string(5) "en-US"
  [1]=>
  string(5) "zh-CN"
  [2]=>
  string(5) "sp-ES"
  [3]=>
  string(5) "fr-FR"
  [4]=>
  string(5) "de-DE"
  [5]=>
  string(5) "pt-PT"
  [6]=>
  string(5) "it-IT"
}
string(6) "global"


4、由于 value 的类型设置为:String,因此,需要将数组转换为 String 格式。否则会验证响应格式失败。


'value' => is_array($value) ? json_encode($value) : $value,


5、”debugMessage”: “Expected a value of type \”String\” but received: [\”en-US\”,\”zh-CN\”,\”sp-ES\”,\”fr-FR\”,\”de-DE\”,\”pt-PT\”,\”it-IT\”]”, 已经消失。符合预期。仅剩下 “debugMessage”: “Cannot return null for non-nullable field \”ThemePreset.sections\”.”。如图3
"debugMessage": "Expected a value of type \"String\" but received: [\"en-US\",\"zh-CN\",\"sp-ES\",\"fr-FR\",\"de-DE\",\"pt-PT\",\"it-IT\"]", 已经消失。符合预期。仅剩下 "debugMessage": "Cannot return null for non-nullable field \"ThemePreset.sections\"."
图3
6、打印 dd($this->resolveSectionSettings($preset, $themeSettingSchema, $id));。


Illuminate\Support\Collection {#11189
  #items: array:3 [
    "header" => null
    "footer" => null
    "announcement-bar" => null
  ]
}


7、最后找到原因,在于集合中的回调函数未 return 。如图4
最后找到原因,在于集合中的回调函数未 return
图4


    private function resolveSectionSettings(ThemeSettingSet $preset, Theme $themeSettingSchema, Id $id)
    {
        $themeId = $this->viewStorage->getThemeId();

        return collect($preset->getSections())
            ->map(function(SectionSetting $sectionSetting, $sectionId) use($themeSettingSchema, $id, $themeId) {
                $sectionSchema = $themeSettingSchema->getSection($sectionId);

                $globalSectionId = $id->with($sectionId);

                return $this->resolveSectionSetting($globalSectionId, $sectionId, $themeId, $sectionSetting, $sectionSchema);
        });
    }


8、请求响应 200。如图5
请求响应 200
图5

PHP / Laravel / Yii2 老项目维护与长期技术支持

如果你的 PHP / Laravel / Yii2 项目已经上线,但遇到原开发离职、Bug 长期无人修复、接口不稳定、性能下降、代码难以接手等问题,可以联系我做一次远程技术排查。

适合以下情况:
✅ 老旧 PHP 系统无人维护
✅ Laravel / Yii2 项目 Bug 修复
✅ 后台管理系统小功能迭代
✅ RESTful API 接口排查
✅ MySQL / Redis / Nginx 性能问题
✅ 长期远程兼职维护

可先从一次小问题开始:
✅ 线上报错排查
✅ 接口异常分析
✅ 慢查询与性能瓶颈定位
✅ 代码结构初步评估
✅ 部署环境与日志检查

如需咨询,请联系我,并注明:PHP 维护咨询

联系方式:
Telegram:@shuijingwan
微信:13980074657
邮箱:shuijingwanwq@gmail.com

评论

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

这个站点使用 Akismet 来减少垃圾评论。了解你的评论数据如何被处理