ChemPal Documentation - v0.0.13-beta.5
    Preparing search index...

    Function isShopifyProductNode

    • 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.

      Parameters

      • product: unknown

        The object to validate

      Returns product is ShopifyProductNode

      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",
      description: "A gold testing kit",
      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 shopifyProductNodeSchema.safeParse(product).success;
      }