【发布时间】:2021-10-04 14:48:20
【问题描述】:
我必须将产品从一个 Shopify 商店转移到另一个。为此,我使用 Shopify GraphQL 管理 API。我在移动数据之前对其进行了转换,因此我无法让 Shopify 帮助我。
无论如何,我从 Shopify 的 API 中获取产品,并将它们存储在 JSON 文件中。每个产品大约有 3,000 行长,包含所有变体类型。
我必须定义查询字段和变量吗?我希望只传递 Shopify 返回的整个 JSON 对象并将其提供给 GraphQL。目前我必须手动定义字段(NodeJS):
const addProduct = (product) => axios.post(apiPath, {
query: `
mutation productCreate($input: ProductInput!) {
productCreate(input: $input) {
userErrors {
field
message
}
product {
title
handle
descriptionHtml
...
}
}
}
`,
variables: {
input: {...product}
}
})
但是这样定义查询字段是一个很长的过程,有没有什么办法可以不用定义查询呢?
这是来自 Shopify 的产品对象的示例。我不得不限制行数:
{
"body_html": " The Air Jordan 3 Retro 'UNC' arrives in March 2020 as an homage to Michael Jordan's alma mater. The special edition presents university-inspired colors on its dual-textured leather upper and eyestays, with elephant print panels granting an iconic touch. Valor Blue hits both Jumpman logos on the tongue and heel while the visible Air unit in the midsole and rubber outsole wrap up the styling. ",
"price_min_usd": 0,
"compare_at_price_max_usd": null,
"available": false,
"review_count": 0,
"percent_sale_min_aud": 0,
"variants": [
{
"merged_options": [
"size:3 UK"
],
"price_cad": "0.00",
"price_usd": "0.00",
"presentment_prices": [
{
"compare_at_price": null,
"price": {
"amount": "0.00",
"currency_code": "AED"
}
},
{
"compare_at_price": null,
"price": {
"amount": "0.00",
"currency_code": "AUD"
}
},
{
"compare_at_price": null,
"price": {
"amount": "0.00",
"currency_code": "CAD"
}
},
{
"compare_at_price": null,
"price": {
"amount": "0.00",
"currency_code": "DKK"
}
},
{
"compare_at_price": null,
"price": {
"amount": "0.00",
"currency_code": "EUR"
}
},
{
"compare_at_price": null,
"price": {
"amount": "0.00",
"currency_code": "GBP"
}
},
{
"compare_at_price": null,
"price": {
"amount": "0.00",
"currency_code": "ILS"
}
},
{
"compare_at_price": null,
"price": {
"amount": "0",
"currency_code": "JPY"
}
},
{
"compare_at_price": null,
"price": {
"amount": "0.00",
"currency_code": "QAR"
}
},
{
"compare_at_price": null,
"price": {
"amount": "0.00",
"currency_code": "SAR"
}
},
{
"compare_at_price": null,
"price": {
"amount": "0.00",
"currency_code": "USD"
}
}
],
"inventory_management": "shopify",
"available": false,
"title": "UK 3 | EU 35.5 | US 3.5",
"price": "0.00",
"price_aed": "0.00",
"id": 40807884062909,
"sku": "CT8532-104.3UK",
"price_eur": "0.00",
"barcode": null,
"price_dkk": "0.00",
"inventory_quantity": 0,
"image": null,
"compare_at_price": null,
"fulfillment_service": "manual",
"price_aud": "0.00",
"price_ils": "0.00",
"price_jpy": "0",
"inventory_policy": "deny",
"price_gbp": "0.00",
"price_qar": "0.00",
"price_sar": "0.00"
},
{
"merged_options": [
"size:3.5 UK"
],
"price_cad": "0.00",
"price_usd": "0.00",
"presentment_prices": [
{
"compare_at_price": null,
"price": {
"amount": "0.00",
"currency_code": "AED"
}
},
{
"compare_at_price": null,
"price": {
"amount": "0.00",
"currency_code": "AUD"
}
},
{
"compare_at_price": null,
"price": {
"amount": "0.00",
"currency_code": "CAD"
}
},
{
"compare_at_price": null,
"price": {
"amount": "0.00",
"currency_code": "DKK"
}
},
{
"compare_at_price": null,
"price": {
"amount": "0.00",
"currency_code": "EUR"
}
},
{
"compare_at_price": null,
"price": {
"amount": "0.00",
"currency_code": "GBP"
}
},
{
"compare_at_price": null,
"price": {
"amount": "0.00",
"currency_code": "ILS"
}
},
{
"compare_at_price": null,
"price": {
"amount": "0",
"currency_code": "JPY"
}
},
{
"compare_at_price": null,
"price": {
"amount": "0.00",
"currency_code": "QAR"
}
},
{
"compare_at_price": null,
"price": {
"amount": "0.00",
"currency_code": "SAR"
}
},
{
"compare_at_price": null,
"price": {
"amount": "0.00",
"currency_code": "USD"
}
}
],
"inventory_management": "shopify",
"available": false,
"title": "UK 3.5 | EU 36 | US 4",
"price": "0.00",
"price_aed": "0.00",
"id": 40807884095677,
"sku": "CT8532-104.3.5UK",
"price_eur": "0.00",
"barcode": null,
"price_dkk": "0.00",
"inventory_quantity": 0,
"image": null,
"compare_at_price": null,
"fulfillment_service": "manual",
"price_aud": "0.00",
"price_ils": "0.00",
"price_jpy": "0",
"inventory_policy": "deny",
"price_gbp": "0.00",
"price_qar": "0.00",
"price_sar": "0.00"
},
{
"merged_options": [
"size:4 UK"
],
"price_cad": "0.00",
"price_usd": "0.00",
"presentment_prices": [
{
"compare_at_price": null,
"price": {
"amount": "0.00",
"currency_code": "AED"
}
},
{
"compare_at_price": null,
"price": {
"amount": "0.00",
"currency_code": "AUD"
}
},
{
【问题讨论】:
标签: shopify shopify-api