Closed czarekowyxjs closed 2 years ago
@czarekowyxjs any update on how to query metafields using js-buy-sdk? Why was this issue closed?
@riccardolardi I closed this issue, because the reason of issue was new version of shopify api where shopify changed the way of querying metafields. I realized it after creating this issue. Now if you want to query any metafield, you have to define it in query args. It works for me:
const metafields = [{
key: "metafield_key",
namespace: 'metafield_namespace',
}, {
key: "metafield_key_2",
namespace: 'metafield_namespace',
}]
export const collectionsWithProductsQuery = client.graphQLClient.query((root: any) => {
root.addConnection('collections', { args: { first: 100 } }, (collection: any) => {
collection.add('title')
collection.addConnection('products', { args: { first: 100 } }, (product: any) => {
product.add('title')
product.add(
'metafields',
{ args: { identifiers: metafields } },
(metafield: any) => {
metafield.add('namespace')
metafield.add('key')
metafield.add('value')
metafield.add('reference', (reference: any) => {
reference.addInlineFragmentOn('MediaImage', (mediaImage: any) => {
mediaImage.add('id')
mediaImage.add('image', (image: any) => {
image.add('id')
image.add('altText')
image.add('height')
image.add('width')
image.add('url')
image.add('transformedSrc')
})
})
})
}
)
})
})
})
@czarekowyxjs thanks a lot, should this work in latest SFAPI 2022-10 ?
Please complete the checklist before filing an issue:
None of the above? Create an issue. Be sure to include all the necessary information for us to understand and reproduce the problem:
Bug details
Describe the bug Product schema has fields metafield and metafields. In version 2.15.1, metafield was type Metafield and metafields was type MetafieldConnection. Now both fields have same type: metafield. It makes impossible to fetch list of metafields for product.
To Reproduce Try to add metafields connection to your request.
Example of request which works for version 2.15.1, but doesn't for 2.16.1:
Expected behavior It should return list of metafields. Exactly as it was in version 2.15.1
Environment (please complete the following information):
Additional context Add any other context about the problem here.
Bug Report Checklist