まずRead product tagsがONか確認
サンプルコードを参考にする
Initializing the Client(リンクページの下の方)
// fetch the large, unoptimized version of the SDK
import Client from 'shopify-buy/index.unoptimized.umd';
const client = Client.buildClient({
domain: 'your-shop-name.myshopify.com',
storefrontAccessToken: 'your-storefront-access-token'
});
Fetching Products(リンクページの下の方)
// Build a custom products query using the unoptimized version of the SDK
const productsQuery = client.graphQLClient.query((root) => {
root.addConnection('products', {args: {first: 10}}, (product) => {
product.add('title');
product.add('tags');// Add fields to be returned
});
});
// Call the send method with the custom products query
client.graphQLClient.send(productsQuery).then(({model, data}) => {
// Do something with the products
console.log(model);
});
ここで注目しないといけないのはClientのimport
// import Client from 'shopify-buy'; ではだめ
import Client from 'shopify-buy/index.unoptimized.umd';