151 lines
2.9 KiB
TypeScript
151 lines
2.9 KiB
TypeScript
import { gql } from '@shopify/hydrogen';
|
|
|
|
// Product Fragment for consistent product data
|
|
export const ProductFragment = gql(`
|
|
fragment ProductFragment on Product {
|
|
id
|
|
title
|
|
handle
|
|
description
|
|
descriptionHtml
|
|
vendor
|
|
productType
|
|
tags
|
|
availableForSale
|
|
priceRange {
|
|
minVariantPrice {
|
|
amount
|
|
currencyCode
|
|
}
|
|
maxVariantPrice {
|
|
amount
|
|
currencyCode
|
|
}
|
|
}
|
|
compareAtPriceRange {
|
|
minVariantPrice {
|
|
amount
|
|
currencyCode
|
|
}
|
|
maxVariantPrice {
|
|
amount
|
|
currencyCode
|
|
}
|
|
}
|
|
images(first: 10) {
|
|
edges {
|
|
node {
|
|
id
|
|
url
|
|
altText
|
|
width
|
|
height
|
|
}
|
|
}
|
|
}
|
|
variants(first: 100) {
|
|
edges {
|
|
node {
|
|
id
|
|
title
|
|
availableForSale
|
|
quantityAvailable
|
|
selectedOptions {
|
|
name
|
|
value
|
|
}
|
|
price {
|
|
amount
|
|
currencyCode
|
|
}
|
|
compareAtPrice {
|
|
amount
|
|
currencyCode
|
|
}
|
|
image {
|
|
id
|
|
url
|
|
altText
|
|
width
|
|
height
|
|
}
|
|
}
|
|
}
|
|
}
|
|
options {
|
|
id
|
|
name
|
|
values
|
|
optionValues {
|
|
id
|
|
name
|
|
swatch {
|
|
color
|
|
image {
|
|
previewImage {
|
|
url
|
|
}
|
|
}
|
|
}
|
|
firstSelectableVariant {
|
|
id
|
|
image {
|
|
id
|
|
url
|
|
altText
|
|
width
|
|
height
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
`);
|
|
|
|
// Get multiple products
|
|
export const GET_PRODUCTS_QUERY = gql(
|
|
`
|
|
query GetProducts($first: Int!, $after: String, $query: String, $sortKey: ProductSortKeys, $reverse: Boolean, $country: CountryCode, $language: LanguageCode)
|
|
@inContext(country: $country, language: $language) {
|
|
products(first: $first, after: $after, query: $query, sortKey: $sortKey, reverse: $reverse) {
|
|
edges {
|
|
node {
|
|
...ProductFragment
|
|
}
|
|
}
|
|
pageInfo {
|
|
hasNextPage
|
|
endCursor
|
|
}
|
|
}
|
|
}
|
|
`,
|
|
[ProductFragment]
|
|
);
|
|
|
|
// Get a single product by handle
|
|
export const GET_PRODUCT_QUERY = gql(
|
|
`
|
|
query GetProduct($handle: String!, $country: CountryCode, $language: LanguageCode)
|
|
@inContext(country: $country, language: $language) {
|
|
product(handle: $handle) {
|
|
...ProductFragment
|
|
}
|
|
}
|
|
`,
|
|
[ProductFragment]
|
|
);
|
|
|
|
// Get product recommendations
|
|
export const QUERY_PRODUCT_RECOMMENDATIONS = gql(
|
|
`
|
|
query GetProductRecommendations($productId: ID!, $country: CountryCode, $language: LanguageCode)
|
|
@inContext(country: $country, language: $language) {
|
|
productRecommendations(productId: $productId) {
|
|
...ProductFragment
|
|
}
|
|
}
|
|
`,
|
|
[ProductFragment]
|
|
);
|