The object to validate
Type predicate indicating if the object is a valid ShopifyProductNode
const product = {
id: "gid://shopify/Product/123",
title: "Gold Test Kit",
handle: "gold-test-kit",
descriptionHtml: "<p>A gold testing kit</p>",
onlineStoreUrl: "https://example.com/products/gold-test-kit",
variants: { edges: [{ node: validVariant }] }
};
if (isShopifyProductNode(product)) {
console.log("Valid product:", product.title);
}
export function isShopifyProductNode(product: unknown): product is ShopifyProductNode {
return v.safeParse(shopifyProductNodeSchema, product).success;
}
Type guard to validate if an object is a valid Shopify product node. Checks for the presence and correct types of all required product properties and validates that all nested variant nodes are also valid.