【问题标题】:Rejoin nested fields in shopify graphql Bulk Operation query在shopify graphql批量操作查询中重新加入嵌套字段
【发布时间】:2020-05-04 17:09:37
【问题描述】:

有没有办法重新加入嵌套字段,因为作为响应,它会分解成单独的对象。

实际反应:

{"id":"gid:\/\/shopify\/Product\/1755556806746","title":"A Book bind","description":"Energize is a pure Sativa formulation designed to stimulate, excite, and keep you productive","productType":"CARTRIDGE","vendor":"ACES","totalInventory":0,"featuredImage":null,"handle":"1g-energizedurban-cart-82-89"}
{"id":"gid:\/\/shopify\/Metafield\/4680431861850","namespace":"custom_fields","key":"thc_percentage","value":"aa","__parentId":"gid:\/\/shopify\/Product\/1755556806746"}
{"id":"gid:\/\/shopify\/Metafield\/4680431894618","namespace":"custom_fields","key":"cbd_percentage","value":"bb","__parentId":"gid:\/\/shopify\/Product\/1755556806746"}
{"id":"gid:\/\/shopify\/Metafield\/4680431960154","namespace":"custom_fields","key":"strain_name","value":"Strain","__parentId":"gid:\/\/shopify\/Product\/1755556806746"}

预期响应:

{"id":"gid:\/\/shopify\/Product\/1755556806746","title":"A Book bind","description":"Energize is a pure Sativa formulation designed to stimulate, excite, and keep you productive","productType":"CARTRIDGE","vendor":"ACES","totalInventory":0,"featuredImage":null,"handle":"1g-energizedurban-cart-82-89",
metafields:[{"id":"gid:\/\/shopify\/Metafield\/4680431861850","namespace":"custom_fields","key":"thc_percentage","value":"aa","__parentId":"gid:\/\/shopify\/Product\/1755556806746"},
{"id":"gid:\/\/shopify\/Metafield\/4680431894618","namespace":"custom_fields","key":"cbd_percentage","value":"bb","__parentId":"gid:\/\/shopify\/Product\/1755556806746"},
{"id":"gid:\/\/shopify\/Metafield\/4680431960154","namespace":"custom_fields","key":"strain_name","value":"Strain","__parentId":"gid:\/\/shopify\/Product\/1755556806746"}
]
}

【问题讨论】:

    标签: graphql shopify shopify-api-node


    【解决方案1】:

    Shopify 使用 JSON Lines (JSONL) 数据类型来输出批量操作的响应。

    文件中的每一行都是连接中返回的一个节点对象。如果一个 节点有一个嵌套连接,然后将每个子节点提取到 下一行是它自己的对象。

    因此,您需要遍历每一行并将其解析为脚本中的 JSON 对象。使用 __parentId 属性作为对父对象的引用。
    如果需要,将其加入父对象,但您只能在收到响应后执行此操作。您不能强制 Shopify API 为您执行此操作。


    有用的链接:

    【讨论】:

      猜你喜欢
      • 2019-08-12
      • 2021-11-20
      • 2019-07-08
      • 2017-01-30
      • 2019-07-18
      • 1970-01-01
      • 2021-01-29
      • 2020-12-02
      • 1970-01-01
      相关资源
      最近更新 更多