import { gql } from 'graphql-request' import { IMAGE_FRAGMENT, PRICE_FRAGMENT } from './fragments' export const CART_FRAGMENT = gql` fragment CartFields on Cart { id checkoutUrl cost { subtotalAmount { ...PriceFields } } totalQuantity discountCodes { code applicable } buyerIdentity { email customer { id } } lines(first: 100) { edges { node { id cost { totalAmount { ...PriceFields } } quantity merchandise { ... on ProductVariant { id product { handle title } image { ...ImageFields } selectedOptions { name value } } } } } } } ` export const CREATE_CART = gql` ${PRICE_FRAGMENT} ${IMAGE_FRAGMENT} ${CART_FRAGMENT} mutation createCart($input: CartInput) { cartCreate(input: $input) { cart { ...CartFields } } } ` export const ADD_TO_CART = gql` ${PRICE_FRAGMENT} ${IMAGE_FRAGMENT} ${CART_FRAGMENT} mutation addToCart($cartId: ID!, $lines: [CartLineInput!]!) { cartLinesAdd(cartId: $cartId, lines: $lines) { cart { ...CartFields } } } ` export const REMOVE_FROM_CART = gql` ${PRICE_FRAGMENT} ${IMAGE_FRAGMENT} ${CART_FRAGMENT} mutation removeFromCart($cartId: ID!, $lineIds: [ID!]!) { cartLinesRemove(cartId: $cartId, lineIds: $lineIds) { cart { ...CartFields } } } ` export const UPDATE_DISCOUNT_CODES = gql` ${PRICE_FRAGMENT} ${IMAGE_FRAGMENT} ${CART_FRAGMENT} mutation updateDiscountCodes($cartId: ID!, $discountCodes: [String!]!) { cartDiscountCodesUpdate( cartId: $cartId discountCodes: $discountCodes ) { cart { ...CartFields } } } ` export const UPDATE_BUYER_ID = gql` ${PRICE_FRAGMENT} ${IMAGE_FRAGMENT} ${CART_FRAGMENT} mutation updateBuyerId( $cartId: ID! $buyerIdentity: CartBuyerIdentityInput! ) { cartBuyerIdentityUpdate( cartId: $cartId buyerIdentity: $buyerIdentity ) { cart { ...CartFields } } } `