Skip to content

Commit

Permalink
refactor(core): use gql.tada on get cart query (#673)
Browse files Browse the repository at this point in the history
  • Loading branch information
deini authored Mar 19, 2024
1 parent b657f6c commit e400945
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 61 deletions.
6 changes: 0 additions & 6 deletions apps/core/client/fragments/money-fields.ts

This file was deleted.

119 changes: 64 additions & 55 deletions apps/core/client/queries/get-cart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,77 +3,86 @@ import { cache } from 'react';
import { getSessionCustomerId } from '~/auth';

import { client } from '..';
import { graphql } from '../generated';
import { graphql } from '../graphql';

export const GET_CART_QUERY = /* GraphQL */ `
query getCart($cartId: String) {
site {
cart(entityId: $cartId) {
entityId
isTaxIncluded
currencyCode
lineItems {
totalQuantity
physicalItems {
name
brand
imageUrl
entityId
quantity
productEntityId
variantEntityId
extendedListPrice {
...MoneyFields
}
extendedSalePrice {
...MoneyFields
}
selectedOptions {
__typename
entityId
const MONEY_FIELDS_FRAGMENT = graphql(`
fragment MoneyFields on Money {
currencyCode
value
}
`);

const GET_CART_QUERY = graphql(
`
query getCart($cartId: String) {
site {
cart(entityId: $cartId) {
entityId
isTaxIncluded
currencyCode
lineItems {
totalQuantity
physicalItems {
name
... on CartSelectedMultipleChoiceOption {
value
valueEntityId
}
... on CartSelectedCheckboxOption {
value
valueEntityId
}
... on CartSelectedNumberFieldOption {
number
}
... on CartSelectedMultiLineTextFieldOption {
text
brand
imageUrl
entityId
quantity
productEntityId
variantEntityId
extendedListPrice {
...MoneyFields
}
... on CartSelectedTextFieldOption {
text
extendedSalePrice {
...MoneyFields
}
... on CartSelectedDateFieldOption {
date {
utc
selectedOptions {
__typename
entityId
name
... on CartSelectedMultipleChoiceOption {
value
valueEntityId
}
... on CartSelectedCheckboxOption {
value
valueEntityId
}
... on CartSelectedNumberFieldOption {
number
}
... on CartSelectedMultiLineTextFieldOption {
text
}
... on CartSelectedTextFieldOption {
text
}
... on CartSelectedDateFieldOption {
date {
utc
}
}
}
}
}
}
amount {
...MoneyFields
}
discountedAmount {
...MoneyFields
amount {
...MoneyFields
}
discountedAmount {
...MoneyFields
}
}
}
}
}
`;
`,
[MONEY_FIELDS_FRAGMENT],
);

export const getCart = cache(async (cartId?: string) => {
const query = graphql(GET_CART_QUERY);
const customerId = await getSessionCustomerId();

const response = await client.fetch({
document: query,
document: GET_CART_QUERY,
variables: { cartId },
customerId,
fetchOptions: {
Expand Down

0 comments on commit e400945

Please sign in to comment.