gpt4 book ai didi

javascript - 使用 Shopify JavaScript Buy SDK 自定义查询检索文章对象,包括其图像

转载 作者:搜寻专家 更新时间:2023-11-01 04:34:39 25 4
gpt4 key购买 nike

我正在使用 shopify-buy SDK 尝试在前端使用 JavaScript 从我的 Shopify 商店获取文章,遵循此处的“扩展 SDK”说明:https://shopify.github.io/js-buy-sdk/#expanding-the-sdk .

使用下面的代码,我能够检索我的文章和我需要的一些字段。

// Build a custom query using the unoptimized version of the SDK
const articlesQuery = client.graphQLClient.query((root) => {
root.addConnection('articles', {args: {first: 10}}, (article) => {
article.add('title')
article.add('handle')
article.add('url')
article.add('contentHtml')
})
})

// Call the send method with the custom query
client.graphQLClient.send(articlesQuery).then(({model, data}) => {
console.log('articles data')
console.log(data)
})

但是,我确实也需要为每篇文章提取特色图片,不幸的是,当我在我的文章查询中添加 article.add('image') 行时,生成的文章数据记录 null。我尝试构建一个自定义 productsQuery,它有一个类似的问题 - 我可以检索一些产品字段,但是当我尝试添加行 product.add('images') 时,我只是得到 null 从店面 API 返回。

有没有人有构建自定义/扩展查询并成功检索图像的经验?

最佳答案

尝试以下操作:

// Fetch all products in your shop
client.graphQLClient.fetchAll().then((acticles) => {
console.log(acticles);
});

然后在控制台中检查您的文章有哪些可用的属性名称。如果 SDK 允许您获取任何图像数据,那么肯定应该有像 imageSrc || 这样的东西imageUrl || img……

关于javascript - 使用 Shopify JavaScript Buy SDK 自定义查询检索文章对象,包括其图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54335603/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com