Schema里能查询自定义字段,也没有报错,但所有商品都返回null。先确认字段是EAV自动暴露,还是自定义Resolver读取。两条链路的修复点不同。

解决方案

  1. 在相同Store View下直接查catalog_product_entity对应backend表,确认目标entity_id、attribute_id、store_id确实有值;没有Store值时应验证是否正确回退到store_id=0。
  2. 若使用ProductInterface扩展字段,Resolver不要从$model数组猜数据。用value中的model或Repository按当前Store读取,并处理简单、可配置、虚拟等商品类型。
  3. 核对schema.graphqls的返回类型。属性是数组或对象却声明为String时,序列化会失败;Dropdown若需要文本,要通过选项源把option_id转为当前Store标签。
  4. 清理config与GraphQL缓存,重新请求一个有值和一个无值商品。若Varnish/FPC参与GraphQL GET缓存,自定义Resolver还要返回正确Identity。
排查命令
SELECT attribute_id,attribute_code,backend_type FROM eav_attribute WHERE attribute_code='vendor_code';
SELECT entity_id,attribute_id,store_id,value FROM catalog_product_entity_varchar WHERE attribute_id=:attribute_id AND entity_id=:entity_id;
bin/magento cache:clean config graphql full_page

回归测试

使用default与第二语言Store Header查询,同一SKU分别返回对应值;无值商品返回明确的null而不是导致整个products查询报错。

不要在每个商品Resolver里单独load一次实体,列表查询会形成N+1;批量加载或使用已提供的数据。