I am simply trying to fetch products by tag with the shopify buy sdk. Unfortunately this is not supported by the SDK by default, so I am forced to "build your own query".
I am able to fetch the products properly, with a few static fields, but fields that are arrays of other data types are not cooperating.
Here was my initial attempt:
product.add('images', (image) => {
image.add('src');
});
I have tried many many variations, but they always end in an error, such as
- there is no field of name "src" found on type "ImageConnection" in schema
- there is no field of name "pageInfo" found on type "ImageEdge" in schema
- there is no field of name "pageInfo" found on type "Image" in schema
- connections must include the selections "pageInfo { hasNextPage, hasPreviousPage }".
- Parse error on "}" (RCURLY) at [1, 217] { line: 1, column: 217 }
here is my full code:
async function getProductsByTag (tag) {
const productsQuery = client.graphQLClient.query((root) => {
root.addConnection('products', { args: { first: 250, query: 'tag:'+tag } }, (product) => {
product.add('title');
product.add('handle');
product.add('productType');
product.add('images', (image) => {
image.add('src');
});
});
});
let result = await client.graphQLClient.send(productsQuery);
return result.data.products.edges.map(p => p.node);
}
This version seems more right, but still returns the No field of name "pageInfo" found on type "ImageEdge" in schema
error.
product.add('images', { args: { first: 250 } }, (imageConnection) => {
imageConnection.addConnection('edges', { args: { first: 250 } }, (image) => {
image.add('node', (node) => {
node.add('src');
});
});
});