Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize query for product page #918

Merged
merged 6 commits into from
Mar 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/new-islands-sleep.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'create-hydrogen-app': patch
---

Optimize the GraphQL query for products page
Original file line number Diff line number Diff line change
Expand Up @@ -32,21 +32,9 @@ export default function Product({country = {isoCode: 'US'}}) {
}

const QUERY = gql`
query product(
$country: CountryCode
$handle: String!
$includeReferenceMetafieldDetails: Boolean = true
$numProductMetafields: Int = 20
$numProductVariants: Int = 250
$numProductMedia: Int = 6
$numProductVariantMetafields: Int = 10
$numProductVariantSellingPlanAllocations: Int = 0
$numProductSellingPlanGroups: Int = 0
$numProductSellingPlans: Int = 0
) @inContext(country: $country) {
query product($country: CountryCode, $handle: String!)
@inContext(country: $country) {
product: product(handle: $handle) {
id
vendor
compareAtPriceRange {
maxVariantPrice {
currencyCode
Expand All @@ -57,10 +45,17 @@ const QUERY = gql`
amount
}
}
description
descriptionHtml
featuredImage {
url
width
height
altText
}
handle
id
media(first: $numProductMedia) {
media(first: 6) {
edges {
node {
... on MediaImage {
Expand Down Expand Up @@ -105,7 +100,7 @@ const QUERY = gql`
}
}
}
metafields(first: $numProductMetafields) {
metafields(first: 20) {
edges {
node {
id
Expand All @@ -116,7 +111,7 @@ const QUERY = gql`
createdAt
updatedAt
description
reference @include(if: $includeReferenceMetafieldDetails) {
reference {
__typename
... on MediaImage {
id
Expand All @@ -143,44 +138,28 @@ const QUERY = gql`
amount
}
}
seo {
description
title
}
title
variants(first: $numProductVariants) {
variants(first: 250) {
edges {
node {
id
title
availableForSale
compareAtPriceV2 {
amount
currencyCode
}
id
image {
id
url
altText
width
height
}
unitPriceMeasurement {
measuredType
quantityUnit
quantityValue
referenceUnit
referenceValue
}
unitPrice {
currencyCode
amount
}
priceV2 {
currencyCode
amount
}
compareAtPriceV2 {
currencyCode
amount
}
selectedOptions {
name
value
}
metafields(first: $numProductVariantMetafields) {
metafields(first: 10) {
edges {
node {
id
Expand All @@ -191,7 +170,7 @@ const QUERY = gql`
createdAt
updatedAt
description
reference @include(if: $includeReferenceMetafieldDetails) {
reference {
__typename
... on MediaImage {
id
Expand All @@ -208,139 +187,31 @@ const QUERY = gql`
}
}
}
sellingPlanAllocations(
first: $numProductVariantSellingPlanAllocations
) {
edges {
node {
priceAdjustments {
compareAtPrice {
currencyCode
amount
}
perDeliveryPrice {
currencyCode
amount
}
price {
currencyCode
amount
}
unitPrice {
currencyCode
amount
}
}
sellingPlan {
id
description
name
options {
name
value
}
priceAdjustments {
orderCount
adjustmentValue {
... on SellingPlanFixedAmountPriceAdjustment {
adjustmentAmount {
currencyCode
amount
}
}
... on SellingPlanFixedPriceAdjustment {
price {
currencyCode
amount
}
}
... on SellingPlanPercentagePriceAdjustment {
adjustmentPercentage
}
}
}
recurringDeliveries
}
}
}
}
}
}
}
sellingPlanGroups(first: $numProductSellingPlanGroups) {
edges {
node {
sellingPlans(first: $numProductSellingPlans) {
edges {
node {
id
description
name
options {
name
value
}
priceAdjustments {
orderCount
adjustmentValue {
... on SellingPlanFixedAmountPriceAdjustment {
adjustmentAmount {
currencyCode
amount
}
}
... on SellingPlanFixedPriceAdjustment {
price {
currencyCode
amount
}
}
... on SellingPlanPercentagePriceAdjustment {
adjustmentPercentage
}
}
}
recurringDeliveries
}
}
priceV2 {
amount
currencyCode
}
appName
name
options {
selectedOptions {
name
values
}
}
}
}
title
description
seo {
description
title
}
vendor
featuredImage {
url
width
height
altText
}
variants(first: $numProductVariants) {
edges {
node {
image {
url
value
}
availableForSale
priceV2 {
sku
title
unitPrice {
amount
currencyCode
}
sku
unitPriceMeasurement {
measuredType
quantityUnit
quantityValue
referenceUnit
referenceValue
}
}
}
}
vendor
}
}
`;