Shopify-获取产品变体的所有图像-GraphQl

时间:2020-10-08 11:11:58

标签: shopify shopify-app shopify-api

我正在使用Shopify作为后端和Nodejs作为前端来构建无头应用程序

使用Shopify应用商店-变体图片企鹅,我已将多个图像添加到变体中。

任何人都可以让我知道如何通过GraphQL获取产品变体的所有图像

预先感谢

1 个答案:

答案 0 :(得分:0)

 Usually variant has only one image so this is how to fetch it:   
 {
      products(first: 20) {
        edges {
          node {
            variants(first: 5) {
              edges {
                node {
                  image {
                    id
                    originalSrc
                  }
                }
              }
            }
            id
            title
          }
        }
      }
    }

但是,如果一个应用程序允许您使用多个应用程序,则意味着它们可以使用以下方法之一:

  1. 将多张图像合并为一张图像-因此,如果下载此图像,您将看到其中的所有图像
  2. 使用Liquide API并将src注入到html中-因此graphQL没有此信息,除非您使用graphQL来获取注入的html(我不确定这是可能的),但无论如何它对您来说都更加复杂和危险因为每个模板都有不同的html

如果要使用完整的nodeJS示例:

const query = `{
  products(first: 20) {
    edges {
      node {
        variants(first: 5) {
          edges {
            node {
              image {
                id
                originalSrc
              }
            }
          }
        }
        id
        title
      }
    }
  }
}`
  const response = await axios({
    headers: {
      "Content-Type": "application/json",
      "X-Shopify-Access-Token": store.accessToken
    },
    method: "post",
    data: {
      query
    },
    url: `https://${store.domain}/admin/api/2020-07/graphql.json`
  });