Shopify / js-buy-sdk

The JS Buy SDK is a lightweight library that allows you to build ecommerce into any website. It is based on Shopify's API and provides the ability to retrieve products and collections from your shop, add products to a cart, and checkout.
https://shopify.github.io/js-buy-sdk
MIT License
984 stars 259 forks source link

Retrieve custom metafield exposed to the store front api [help wanted] #769

Open GaspardC opened 4 years ago

GaspardC commented 4 years ago

Hello 😊

I cannot manage to access custom meta fields,

I'm using: import Client from 'shopify-buy/index.unoptimized.umd'; and "shopify-buy": "^2.10.0"

I've whiltelisted my custom metafield dateFromto make it accessible (I can retrieve them from the GraphiQL client with the strore front api) :

Capture d’écran 2020-07-06 à 09 04 03
   product.addConnection('metafields', { args: { first: 1 } }, (metafield) => {
                metafield.add('dateFrom')  // NOT working
                metafield.add('createdAt') // working
                metafield.add('namespace') // working
                metafield.add('key')       // working
                metafield.add('value')     // working
            })

I get the error : Error: No field of name "dateFrom" found on type "Metafield" in schema

What am I missing here ?

thanks Gaspard

jornwildenbeest commented 3 years ago

dateFrom is the key value, my best guess is that it's in the "value" item.

  product.addConnection('metafields', { args: { first: 1 } }, (metafield) => {
                metafield.add('createdAt') // working
                metafield.add('namespace') // working
                metafield.add('key')       // working
                metafield.add('value')     // <-- this one holds the dateFrom value.
            })

If I am right the "dateFrom" should be in the value

sstottelaar commented 3 years ago

I couldn't find any info on how to retrieve the metafields through the SDK custom queries, thanks for this. This should be in the documentation imo!