Skip to content
This repository has been archived by the owner on Mar 3, 2023. It is now read-only.

Commit

Permalink
add graphql comments, remove duplicated query, add new field names (#94)
Browse files Browse the repository at this point in the history
  • Loading branch information
frehner authored Dec 14, 2022
1 parent de1429e commit f570f72
Show file tree
Hide file tree
Showing 3 changed files with 207 additions and 252 deletions.
9 changes: 9 additions & 0 deletions .changeset/clever-plants-wink.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
'@shopify/hydrogen-react': patch
---

Added the `price` and `compareAtPrice` fields to our `defaultCartFragment`, which is used to get the Cart fields in the `<CartProvider />` component.

The above fields should be identical to `priceV2` and `compareAtPriceV2`, with the exception that these `V2` fields are being deprecated in a future version of the Storefront API.

We'll keep both for now, to help deveopers upgrade without issues, and then remove the `V2` versions in a future breaking update.
104 changes: 2 additions & 102 deletions packages/react/src/CartProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import {
import {useCartAPIStateMachine} from './useCartAPIStateMachine.js';
import {CART_ID_STORAGE_KEY} from './cart-constants.js';
import {PartialDeep} from 'type-fest';
import {defaultCartFragment} from './cart-queries.js';

export const CartContext = createContext<CartWithActions | null>(null);

Expand Down Expand Up @@ -133,7 +134,7 @@ export function CartProvider({
data: cart,
cartFragment,
countryCode,
onCartActionEntry(context, event) {
onCartActionEntry(_, event) {
try {
switch (event.type) {
case 'CART_CREATE':
Expand Down Expand Up @@ -523,104 +524,3 @@ function countryCodeNotUpdated(
event.payload.buyerIdentity.countryCode
);
}

export const defaultCartFragment = `
fragment CartFragment on Cart {
id
checkoutUrl
totalQuantity
buyerIdentity {
countryCode
customer {
id
email
firstName
lastName
displayName
}
email
phone
}
lines(first: $numCartLines) {
edges {
node {
id
quantity
attributes {
key
value
}
cost {
totalAmount {
amount
currencyCode
}
compareAtAmountPerQuantity {
amount
currencyCode
}
}
merchandise {
... on ProductVariant {
id
availableForSale
compareAtPriceV2 {
...MoneyFragment
}
priceV2 {
...MoneyFragment
}
requiresShipping
title
image {
...ImageFragment
}
product {
handle
title
}
selectedOptions {
name
value
}
}
}
}
}
}
cost {
subtotalAmount {
...MoneyFragment
}
totalAmount {
...MoneyFragment
}
totalDutyAmount {
...MoneyFragment
}
totalTaxAmount {
...MoneyFragment
}
}
note
attributes {
key
value
}
discountCodes {
code
}
}
fragment MoneyFragment on MoneyV2 {
currencyCode
amount
}
fragment ImageFragment on Image {
id
url
altText
width
height
}
`;
Loading

0 comments on commit f570f72

Please sign in to comment.