在 shopify graphql 批量操作查询中重新加入嵌套字段

Rejoin nested fields in shopify graphql Bulk Operation query

有什么方法可以重新加入嵌套字段,因为作为响应,它会分解成单独的对象。

实际响应:

{"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"}
]
}

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

Each line in the file is a node object returned in a connection. If a node has a nested connection, then each child node is extracted into its own object on the next line.

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


有用的链接: