# QUERIES

query FetchCart($id: ID!) {
  cart(id: $id) {
    ...Cart
  }
}

query FetchCollections {
  collections(first: 250) {
    nodes {
      ...Collection
    }
  }
}

# MUTATIONS

mutation CreateCart {
  cartCreate {
    ...CartCreatePayload
  }
}
mutation CreateCartWithLines($lines: [CartLineInput!]!) {
  cartCreate(input: { lines: $lines }) {
    ...CartCreatePayload
  }
}

mutation AddLineItem($cartId: ID!, $lines: [CartLineInput!]!) {
  cartLinesAdd(cartId: $cartId, lines: $lines) {
    cart {
      ...Cart
    }
    userErrors {
      code
      field
      message
    }
  }
}

mutation UpdateLineItem($cartId: ID!, $lines: [CartLineUpdateInput!]!) {
  cartLinesUpdate(cartId: $cartId, lines: $lines) {
    cart {
      ...Cart
    }
    userErrors {
      code
      field
      message
    }
  }
}

mutation RemoveLineItem($cartId: ID!, $lineIds: [ID!]!) {
  cartLinesRemove(cartId: $cartId, lineIds: $lineIds) {
    cart {
      ...Cart
    }
    userErrors {
      code
      field
      message
    }
  }
}

# FRAGMENTS

fragment Image on Image {
  id
  altText
  url
  width
  height
}

fragment Cart on Cart {
  id
  checkoutUrl
  lines(first: 250) {
    nodes {
      id
      quantity
      merchandise {
        ... on ProductVariant {
          id
          selectedOptions {
            name
            value
          }
          title
          priceV2 {
            amount
            currencyCode
          }
          image {
            ...Image
          }
          product {
            id
            title
            handle
            description
          }
        }
      }
      cost {
        subtotalAmount {
          amount
          currencyCode
        }
      }
    }
  }
  cost {
    subtotalAmount {
      amount
      currencyCode
    }
  }
}

fragment CartCreatePayload on CartCreatePayload {
  cart {
    ...Cart
  }
  userErrors {
    code
    field
    message
  }
}

fragment Collection on Collection {
  id
  title
  handle
  descriptionHtml
  products(first: 250) {
    nodes {
      ...Product
    }
  }
}

fragment Product on Product {
  id
  title
  descriptionHtml
  handle
  productType
  tags
  options {
    name
    values
  }
  variants(first: 250) {
    nodes {
      ...ProductVariant
    }
  }
  priceRange {
    minVariantPrice {
      amount
      currencyCode
    }
    maxVariantPrice {
      amount
      currencyCode
    }
  }
  productType
  onlineStoreUrl
  availableForSale
  images(first: 20) {
    nodes {
      ...Image
    }
  }
}

fragment ProductVariant on ProductVariant {
  id
  title
  availableForSale
  quantityAvailable
  compareAtPriceV2 {
    amount
    currencyCode
  }
  priceV2 {
    amount
    currencyCode
  }
  image {
    ...Image
  }
  selectedOptions {
    name
    value
  }
}
