【问题标题】:Shopify GraphQL inaccurate responseShopify GraphQL 响应不准确
【发布时间】:2020-09-09 03:51:19
【问题描述】:

我正在使用 Shopify 的 GraphQL 工具来验证我的查询是否正确,并且它的响应与我期望看到的一样

这是我在店面使用的代码。

const query = `{
  products(first: 1, query: "sku:[DUMMY_SKU_HERE]") {
    edges {
      node {
        id
        handle
        onlineStoreUrl
        title
        images(first: 1) {
          edges {
            node {
              transformedSrc(maxWidth: 100, maxHeight: 100)
            }
          }
        }
      }
    }
  }
}`;

fetch("https://dummystore.myshopify.com/api/2020-07/graphql", {
  method: "POST",
  headers: {
    Accept: "application/json",
    "Content-Type": "application/graphql",
    "X-Shopify-Storefront-Access-Token": access_token,
  },
  body: query,
})
.then((response) => response.json())
.then((response) => {
  console.log(response);
})
.catch((error) => console.error(error));

这是我从 Shopify 得到的非常不正确的回复。它不仅不正确,而且无论我为查询传递什么 SKU,它都会返回完全相同的产品数据。

【问题讨论】:

    标签: graphql shopify liquid


    【解决方案1】:

    您将 Admin GraphQL 与 Storefront GraphQL 混淆了。

    products 的可用 Storefront GraphQL query 参数是:

    available_for_sale
    created_at
    product_type
    tag
    title
    updated_at
    variants.price
    vendor
    

    那里没有 SKU。

    您的屏幕截图似乎显示了与 Admin GraphQL API 相关联的 GraphiQL Shopify 应用程序,而不是 Storefront GraphQL API。

    这就是你得到相同结果的原因,因为查询被忽略了。

    【讨论】:

    • 你从哪里得到这些信息的?我一直在挖掘文档,它们都开始模糊在一起。
    • 感谢您的信息,可惜没有办法做到这一点,但至少现在我知道为什么了。
    猜你喜欢
    • 2021-10-22
    • 1970-01-01
    • 1970-01-01
    • 2020-07-27
    • 1970-01-01
    • 1970-01-01
    • 2021-04-10
    • 2020-04-22
    • 2019-04-06
    相关资源
    最近更新 更多