Skip to main content

๐Ÿ“ฆ FetchProductResult Type

The getProduct() function returns an object of type FetchProductResult, which includes both the product data and any error encountered during the fetch.


๐Ÿง  Structureโ€‹

type FetchProductResult = {
data: Product | null;
error: string | null;
}

You should always check both data and error:

const { data, error } = await getProduct(...);

if (error || !data) {
console.error("Error loading product:", error);
}

๐Ÿ›๏ธ Product Typeโ€‹

The main data object has the following structure:

interface Product {
id: string;
title: string;
handle: string;
descriptionHtml: string;
featuredImage: {
originalSrc: string;
altText: string | null;
} | null;
images: Array<{
originalSrc: string;
altText: string | null;
}>;
variants: Variant[];
price: {
amount: number;
currencyCode: string;
};
compareAtPrice?: {
amount: number;
currencyCode: string;
} | null;
metafields?: Record<string, Record<string, any>>;
}

๐Ÿงช Exampleโ€‹

{
id: "gid://shopify/Product/123456789",
title: "Solar Panel Kit 6kW",
handle: "solar-kit-6kw",
descriptionHtml: "<p>High-efficiency solar kit.</p>",
featuredImage: {
originalSrc: "https://cdn.shopify.com/s/files/...",
altText: "Main product image"
},
images: [...],
variants: [...],
price: {
amount: 4999,
currencyCode: "EUR"
},
metafields: {
custom: {
brand: "SolarTech",
weight: 45.5,
warranty: "25 years"
}
}
}

๐Ÿ”„ variants: Variant[]โ€‹

Each variant follows this structure:

interface Variant {
id: string;
variantTitle: string;
productTitle: string;
price: {
amount: number;
currencyCode: string;
};
compareAtPrice?: {
amount: number;
currencyCode: string;
} | null;
metafields?: Record<string, Record<string, any>>;
}

โœ… Notes:โ€‹

  • If the variant title is "Default Title", it will be replaced with the product title for consistency.
  • If variantMetafields are provided in the options, each variant's metafields will be typed and parsed the same way as product-level metafields.
  • You can enrich each variant with transformVariantMetafields.

๐Ÿงฉ metafieldsโ€‹

The metafields object is:

  • Nested by namespace (e.g., custom)
  • Keys can be camelCased if camelizeKeys: true
  • Types are automatically cast
  • Rich text and files are processed if enabled in options
data.metafields.custom.weight // โ†’ 45.5
data.metafields.custom.warranty // โ†’ "25 years"

๐Ÿง  Summaryโ€‹

FieldDescription
dataA structured Product object, or null if not found
errorA string describing what went wrong, or null

Next: Back to Overview โ†’

Description

Learn about the return structure of getProduct, including product data, variants, and parsed metafields.