import { gql } from 'graphql-request' import { IMAGE_FRAGMENT, PRICE_FRAGMENT } from './fragments' // Base fragment for product // with product metafield of a list of files (images) // called 'community_images' export const PRODUCT_FRAGMENT = gql` fragment ProductFields on Product { id handle title descriptionHtml metafields( identifiers: [ { namespace: "custom", key: "community_images" } { namespace: "custom", key: "size_guide" } { namespace: "custom", key: "member_gated" } { namespace: "custom", key: "member_discounted" } ] ) { key namespace id type value references(first: 100) { edges { node { ... on MediaImage { image { ...ImageFields } } } } } } featuredImage { ...ImageFields } priceRange { minVariantPrice { ...PriceFields } } options { id name optionValues { id name } } sellingPlanGroups(first: 1) { edges { node { name options { name values } sellingPlans(first: 3) { edges { node { id name description recurringDeliveries options { name value } } } } } } } } ` export const GET_PRODUCTS = gql` ${IMAGE_FRAGMENT} ${PRICE_FRAGMENT} ${PRODUCT_FRAGMENT} query getProducts($first: Int!) { products(first: $first) { edges { node { ...ProductFields } } } } ` export const GET_PRODUCT_BY_HANDLE = gql` ${IMAGE_FRAGMENT} ${PRICE_FRAGMENT} ${PRODUCT_FRAGMENT} query getProductByHandle($handle: String!) { product(handle: $handle) { ...ProductFields images(first: 100) { edges { node { ...ImageFields } } } variants(first: 100) { edges { node { id title selectedOptions { name value } price { ...PriceFields } availableForSale } } } } } ` export const GET_PRODUCT_RECOMMENDATIONS = gql` ${IMAGE_FRAGMENT} ${PRICE_FRAGMENT} ${PRODUCT_FRAGMENT} query getProductRecommendations($handle: String!) { productRecommendations(productHandle: $handle) { ...ProductFields } } `