Files
nextjs-shopify-products/graphql/products.js
2026-04-19 11:15:11 -04:00

117 lines
2.1 KiB
JavaScript

// Product Fragment for consistent product data
export const ProductFragment = `
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
selectedOptions {
name
value
}
price {
amount
currencyCode
}
compareAtPrice {
amount
currencyCode
}
image {
id
url
altText
width
height
}
}
}
}
options {
id
name
values
}
}
`;
// Get multiple products
export const GET_PRODUCTS_QUERY = `
${ProductFragment}
query GetProducts($first: Int!, $query: String, $sortKey: ProductSortKeys, $reverse: Boolean) {
products(first: $first, query: $query, sortKey: $sortKey, reverse: $reverse) {
edges {
node {
...ProductFragment
}
}
pageInfo {
hasNextPage
endCursor
}
}
}
`;
// Get a single product by handle
export const GET_PRODUCT_QUERY = `
${ProductFragment}
query GetProduct($handle: String!) {
product(handle: $handle) {
...ProductFragment
}
}
`;
// Get product recommendations
export const QUERY_PRODUCT_RECOMMENDATIONS = `
${ProductFragment}
query GetProductRecommendations($productId: ID!) {
productRecommendations(productId: $productId) {
...ProductFragment
}
}
`;