-
Notifications
You must be signed in to change notification settings - Fork 267
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix the
OptimisticCart
type to properly retain the generic of line …
…items (#2327) * Fix the `OptimisticCart` type to properly retain the generic of line items * Make `OptimisticCartLine` support both Cart and CartLine as a generic
- Loading branch information
Showing
9 changed files
with
229 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@shopify/hydrogen': patch | ||
--- | ||
|
||
Fix the `OptimisticCart` type to properly retain the generic of line items. The `OptimisticCartLine` type now takes a cart or cart line item generic. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,183 @@ | ||
// NOTE: https://shopify.dev/docs/api/storefront/latest/queries/cart | ||
export const CART_QUERY_FRAGMENT = `#graphql | ||
fragment Money on MoneyV2 { | ||
currencyCode | ||
amount | ||
} | ||
fragment CartLine on CartLine { | ||
id | ||
quantity | ||
attributes { | ||
key | ||
value | ||
} | ||
cost { | ||
totalAmount { | ||
...Money | ||
} | ||
amountPerQuantity { | ||
...Money | ||
} | ||
compareAtAmountPerQuantity { | ||
...Money | ||
} | ||
} | ||
#/***********************************************/ | ||
#/********** EXAMPLE UPDATE STARTS ************/ | ||
sellingPlanAllocation { | ||
sellingPlan { | ||
name | ||
} | ||
} | ||
#/***********************************************/ | ||
#/********** EXAMPLE UPDATE ENDS ************/ | ||
merchandise { | ||
... on ProductVariant { | ||
id | ||
availableForSale | ||
compareAtPrice { | ||
...Money | ||
} | ||
price { | ||
...Money | ||
} | ||
requiresShipping | ||
title | ||
image { | ||
id | ||
url | ||
altText | ||
width | ||
height | ||
} | ||
product { | ||
handle | ||
title | ||
id | ||
vendor | ||
} | ||
selectedOptions { | ||
name | ||
value | ||
} | ||
} | ||
} | ||
} | ||
fragment CartApiQuery on Cart { | ||
updatedAt | ||
id | ||
checkoutUrl | ||
totalQuantity | ||
buyerIdentity { | ||
countryCode | ||
customer { | ||
id | ||
firstName | ||
lastName | ||
displayName | ||
} | ||
phone | ||
} | ||
lines(first: $numCartLines) { | ||
nodes { | ||
...CartLine | ||
} | ||
} | ||
cost { | ||
subtotalAmount { | ||
...Money | ||
} | ||
totalAmount { | ||
...Money | ||
} | ||
totalDutyAmount { | ||
...Money | ||
} | ||
totalTaxAmount { | ||
...Money | ||
} | ||
} | ||
note | ||
attributes { | ||
key | ||
value | ||
} | ||
discountCodes { | ||
code | ||
applicable | ||
} | ||
} | ||
` as const; | ||
|
||
const MENU_FRAGMENT = `#graphql | ||
fragment MenuItem on MenuItem { | ||
id | ||
resourceId | ||
tags | ||
title | ||
type | ||
url | ||
} | ||
fragment ChildMenuItem on MenuItem { | ||
...MenuItem | ||
} | ||
fragment ParentMenuItem on MenuItem { | ||
...MenuItem | ||
items { | ||
...ChildMenuItem | ||
} | ||
} | ||
fragment Menu on Menu { | ||
id | ||
items { | ||
...ParentMenuItem | ||
} | ||
} | ||
` as const; | ||
|
||
export const HEADER_QUERY = `#graphql | ||
fragment Shop on Shop { | ||
id | ||
name | ||
description | ||
primaryDomain { | ||
url | ||
} | ||
brand { | ||
logo { | ||
image { | ||
url | ||
} | ||
} | ||
} | ||
} | ||
query Header( | ||
$country: CountryCode | ||
$headerMenuHandle: String! | ||
$language: LanguageCode | ||
) @inContext(language: $language, country: $country) { | ||
shop { | ||
...Shop | ||
} | ||
menu(handle: $headerMenuHandle) { | ||
...Menu | ||
} | ||
} | ||
${MENU_FRAGMENT} | ||
` as const; | ||
|
||
export const FOOTER_QUERY = `#graphql | ||
query Footer( | ||
$country: CountryCode | ||
$footerMenuHandle: String! | ||
$language: LanguageCode | ||
) @inContext(language: $language, country: $country) { | ||
menu(handle: $footerMenuHandle) { | ||
...Menu | ||
} | ||
} | ||
${MENU_FRAGMENT} | ||
` as const; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.