-
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Okay, I've figured by myself. const PRODUCT_IMAGE_FRAGMENT = `#graphql
fragment ProductMediaImage on MediaImage {
__typename
mediaContentType
image {
__typename
id
url
altText
width
height
}
}
` as const;
const PRODUCT_EXTERNAL_VIDEO_FRAGMENT = `#graphql
fragment ProductExternalVideo on ExternalVideo {
mediaContentType
id
embedUrl
host
originUrl
presentation {
id
}
previewImage {
id
url
width
height
altText
}
}
` as const;
const PRODUCT_VIDEO_FRAGMENT = `#graphql
fragment ProductVideo on Video {
id
mediaContentType
previewImage {
id
url
width
height
altText
}
}
` as const;
const PRODUCT_FRAGMENT = `#graphql
fragment Product on Product {
id
title
vendor
handle
descriptionHtml
description
options {
name
values
}
media(first: 10) {
nodes {
...ProductMediaImage
...ProductExternalVideo
...ProductVideo
}
}
selectedVariant: variantBySelectedOptions(selectedOptions: $selectedOptions, ignoreUnknownOptions: true, caseInsensitiveMatch: true) {
...ProductVariant
}
variants(first: 1) {
nodes {
...ProductVariant
}
}
seo {
description
title
}
}
${PRODUCT_VARIANT_FRAGMENT}
${PRODUCT_IMAGE_FRAGMENT}
${PRODUCT_EXTERNAL_VIDEO_FRAGMENT}
${PRODUCT_VIDEO_FRAGMENT}
` as const; Initially I was struggling to make this work because:
So either Shopify documentation or Hydrogen implementation is wrong. If you look at this object on Shopify Docs: You will see it has a If you open node_modules, you can see the Image type was defined with a Technically, it would not be a problem, since __typename is a technical field from GraphQL, and should be automatically added to every graphql object, but for some reason in Hydrogen this is not as seemeless as one could think, so I had to add it manually. I've fixed the problem by adding |
Beta Was this translation helpful? Give feedback.
Okay, I've figured by myself.
This is the code that solved the problem: