From 5ceb134d33e5d5e089fec2fabc0b78b71040ad7b Mon Sep 17 00:00:00 2001 From: cond0r <1243434+cond0r@users.noreply.github.com> Date: Tue, 31 Jan 2023 09:11:58 +0200 Subject: [PATCH] Cart API --- packages/shopify/codegen.json | 2 +- packages/shopify/schema.d.ts | 1244 +++++++++++------ packages/shopify/schema.graphql | 548 +++++++- .../api/endpoints/checkout/get-checkout.ts | 27 +- packages/shopify/src/api/index.ts | 4 +- packages/shopify/src/cart/use-add-item.tsx | 51 +- packages/shopify/src/cart/use-cart.tsx | 37 +- packages/shopify/src/cart/use-remove-item.tsx | 46 +- packages/shopify/src/cart/use-update-item.tsx | 35 +- packages/shopify/src/const.ts | 6 +- packages/shopify/src/provider.ts | 4 +- packages/shopify/src/utils/cart.ts | 65 + packages/shopify/src/utils/checkout-create.ts | 45 - .../shopify/src/utils/checkout-to-cart.ts | 41 - .../utils/fragments/cart-details-fragment.ts | 82 ++ packages/shopify/src/utils/get-checkout-id.ts | 8 - packages/shopify/src/utils/index.ts | 3 - .../src/utils/mutations/cart-mutations.ts | 64 + .../src/utils/mutations/checkout-create.ts | 19 - .../utils/mutations/checkout-line-item-add.ts | 22 - .../mutations/checkout-line-item-remove.ts | 21 - .../mutations/checkout-line-item-update.ts | 22 - packages/shopify/src/utils/mutations/index.ts | 4 - packages/shopify/src/utils/normalize.ts | 76 +- .../src/utils/queries/get-all-pages-query.ts | 2 +- .../src/utils/queries/get-cart-query.ts | 10 + .../src/utils/queries/get-checkout-query.ts | 70 - .../utils/queries/get-customer-id-query.ts | 2 +- .../src/utils/queries/get-customer-query.ts | 2 +- .../src/utils/queries/get-page-query.ts | 2 +- .../src/utils/queries/get-product-query.ts | 4 +- packages/shopify/src/utils/queries/index.ts | 1 - .../shopify/src/utils/throw-user-errors.ts | 9 +- 33 files changed, 1664 insertions(+), 914 deletions(-) create mode 100644 packages/shopify/src/utils/cart.ts delete mode 100644 packages/shopify/src/utils/checkout-create.ts delete mode 100644 packages/shopify/src/utils/checkout-to-cart.ts create mode 100644 packages/shopify/src/utils/fragments/cart-details-fragment.ts delete mode 100644 packages/shopify/src/utils/get-checkout-id.ts create mode 100644 packages/shopify/src/utils/mutations/cart-mutations.ts delete mode 100644 packages/shopify/src/utils/mutations/checkout-create.ts delete mode 100644 packages/shopify/src/utils/mutations/checkout-line-item-add.ts delete mode 100644 packages/shopify/src/utils/mutations/checkout-line-item-remove.ts delete mode 100644 packages/shopify/src/utils/mutations/checkout-line-item-update.ts create mode 100644 packages/shopify/src/utils/queries/get-cart-query.ts delete mode 100644 packages/shopify/src/utils/queries/get-checkout-query.ts diff --git a/packages/shopify/codegen.json b/packages/shopify/codegen.json index 157a2dcd6..424aada4b 100644 --- a/packages/shopify/codegen.json +++ b/packages/shopify/codegen.json @@ -1,6 +1,6 @@ { "schema": { - "https://${NEXT_PUBLIC_SHOPIFY_STORE_DOMAIN}/api/2022-07/graphql.json": { + "https://${NEXT_PUBLIC_SHOPIFY_STORE_DOMAIN}/api/2023-01/graphql.json": { "headers": { "X-Shopify-Storefront-Access-Token": "${NEXT_PUBLIC_SHOPIFY_STOREFRONT_ACCESS_TOKEN}" } diff --git a/packages/shopify/schema.d.ts b/packages/shopify/schema.d.ts index 6b5dce743..daead474c 100644 --- a/packages/shopify/schema.d.ts +++ b/packages/shopify/schema.d.ts @@ -16,12 +16,13 @@ export type Scalars = { Boolean: boolean Int: number Float: number + Color: any DateTime: any Decimal: any HTML: any JSON: any - Money: any URL: any + UnsignedInt64: any } /** @@ -42,19 +43,19 @@ export type ApiVersion = { /** Details about the gift card used on the checkout. */ export type AppliedGiftCard = Node & { __typename?: 'AppliedGiftCard' + /** The amount that was taken from the gift card by applying it. */ + amountUsed: MoneyV2 /** * The amount that was taken from the gift card by applying it. - * @deprecated Use `amountUsedV2` instead. + * @deprecated Use `amountUsed` instead. */ - amountUsed: Scalars['Money'] - /** The amount that was taken from the gift card by applying it. */ amountUsedV2: MoneyV2 + /** The amount left on the gift card. */ + balance: MoneyV2 /** * The amount left on the gift card. - * @deprecated Use `balanceV2` instead. + * @deprecated Use `balance` instead. */ - balance: Scalars['Money'] - /** The amount left on the gift card. */ balanceV2: MoneyV2 /** A globally-unique identifier. */ id: Scalars['ID'] @@ -360,6 +361,50 @@ export enum BlogSortKeys { Title = 'TITLE', } +/** + * The store's branding configuration. + * + */ +export type Brand = { + __typename?: 'Brand' + /** The colors of the store's brand. */ + colors: BrandColors + /** The store's cover image. */ + coverImage?: Maybe + /** The store's default logo. */ + logo?: Maybe + /** The store's short description. */ + shortDescription?: Maybe + /** The store's slogan. */ + slogan?: Maybe + /** The store's preferred logo for square UI elements. */ + squareLogo?: Maybe +} + +/** + * A group of related colors for the shop's brand. + * + */ +export type BrandColorGroup = { + __typename?: 'BrandColorGroup' + /** The background color. */ + background?: Maybe + /** The foreground color. */ + foreground?: Maybe +} + +/** + * The colors of the shop's brand. + * + */ +export type BrandColors = { + __typename?: 'BrandColors' + /** The shop's primary brand colors. */ + primary: Array + /** The shop's secondary brand colors. */ + secondary: Array +} + /** Card brand, such as Visa or Mastercard, which can be used for payments. */ export enum CardBrand { /** American Express. */ @@ -376,7 +421,13 @@ export enum CardBrand { Visa = 'VISA', } -/** A cart represents the merchandise that a buyer intends to purchase, and the estimated cost associated with the cart. To learn how to interact with a cart during a customer's session, refer to [Manage a cart with the Storefront API](https://shopify.dev/api/examples/cart). */ +/** + * A cart represents the merchandise that a buyer intends to purchase, + * and the estimated cost associated with the cart. Learn how to + * [interact with a cart](https://shopify.dev/custom-storefronts/internationalization/international-pricing) + * during a customer's session. + * + */ export type Cart = Node & { __typename?: 'Cart' /** An attribute associated with the cart. */ @@ -387,11 +438,15 @@ export type Cart = Node & { buyerIdentity: CartBuyerIdentity /** The URL of the checkout for the cart. */ checkoutUrl: Scalars['URL'] - /** The estimated costs that the buyer will pay at checkout. The costs are subject to change and changes will be reflected at checkout. The `cost` field uses the `buyerIdentity` field to determine [international pricing](https://shopify.dev/api/examples/international-pricing#create-a-cart). */ + /** The estimated costs that the buyer will pay at checkout. The costs are subject to change and changes will be reflected at checkout. The `cost` field uses the `buyerIdentity` field to determine [international pricing](https://shopify.dev/custom-storefronts/internationalization/international-pricing). */ cost: CartCost /** The date and time when the cart was created. */ createdAt: Scalars['DateTime'] - /** The delivery groups available for the cart, based on the default address of the logged-in customer. */ + /** + * The delivery groups available for the cart, based on the buyer identity default + * delivery address preference or the default address of the logged-in customer. + * + */ deliveryGroups: CartDeliveryGroupConnection /** The discounts that have been applied to the entire cart. */ discountAllocations: Array @@ -401,7 +456,11 @@ export type Cart = Node & { */ discountCodes: Array /** - * The estimated costs that the buyer will pay at checkout. The estimated costs are subject to change and changes will be reflected at checkout. The `estimatedCost` field uses the `buyerIdentity` field to determine [international pricing](https://shopify.dev/api/examples/international-pricing#create-a-cart). + * The estimated costs that the buyer will pay at checkout. + * The estimated costs are subject to change and changes will be reflected at checkout. + * The `estimatedCost` field uses the `buyerIdentity` field to determine + * [international pricing](https://shopify.dev/custom-storefronts/internationalization/international-pricing). + * * @deprecated Use `cost` instead. */ estimatedCost: CartEstimatedCost @@ -417,12 +476,24 @@ export type Cart = Node & { updatedAt: Scalars['DateTime'] } -/** A cart represents the merchandise that a buyer intends to purchase, and the estimated cost associated with the cart. To learn how to interact with a cart during a customer's session, refer to [Manage a cart with the Storefront API](https://shopify.dev/api/examples/cart). */ +/** + * A cart represents the merchandise that a buyer intends to purchase, + * and the estimated cost associated with the cart. Learn how to + * [interact with a cart](https://shopify.dev/custom-storefronts/internationalization/international-pricing) + * during a customer's session. + * + */ export type CartAttributeArgs = { key: Scalars['String'] } -/** A cart represents the merchandise that a buyer intends to purchase, and the estimated cost associated with the cart. To learn how to interact with a cart during a customer's session, refer to [Manage a cart with the Storefront API](https://shopify.dev/api/examples/cart). */ +/** + * A cart represents the merchandise that a buyer intends to purchase, + * and the estimated cost associated with the cart. Learn how to + * [interact with a cart](https://shopify.dev/custom-storefronts/internationalization/international-pricing) + * during a customer's session. + * + */ export type CartDeliveryGroupsArgs = { after?: InputMaybe before?: InputMaybe @@ -431,7 +502,13 @@ export type CartDeliveryGroupsArgs = { reverse?: InputMaybe } -/** A cart represents the merchandise that a buyer intends to purchase, and the estimated cost associated with the cart. To learn how to interact with a cart during a customer's session, refer to [Manage a cart with the Storefront API](https://shopify.dev/api/examples/cart). */ +/** + * A cart represents the merchandise that a buyer intends to purchase, + * and the estimated cost associated with the cart. Learn how to + * [interact with a cart](https://shopify.dev/custom-storefronts/internationalization/international-pricing) + * during a customer's session. + * + */ export type CartLinesArgs = { after?: InputMaybe before?: InputMaybe @@ -465,6 +542,13 @@ export type CartBuyerIdentity = { countryCode?: Maybe /** The customer account associated with the cart. */ customer?: Maybe + /** + * An ordered set of delivery addresses tied to the buyer that is interacting with the cart. + * The rank of the preferences is determined by the order of the addresses in the array. Preferences + * can be used to populate relevant fields in the checkout flow. + * + */ + deliveryAddressPreferences: Array /** The email address of the buyer that is interacting with the cart. */ email?: Maybe /** The phone number of the buyer that is interacting with the cart. */ @@ -474,7 +558,7 @@ export type CartBuyerIdentity = { /** * Specifies the input fields to update the buyer information associated with a cart. * Buyer identity is used to determine - * [international pricing](https://shopify.dev/api/examples/international-pricing#create-a-checkout) + * [international pricing](https://shopify.dev/custom-storefronts/internationalization/international-pricing) * and should match the customer's shipping address. * */ @@ -483,6 +567,13 @@ export type CartBuyerIdentityInput = { countryCode?: InputMaybe /** The access token used to identify the customer associated with the cart. */ customerAccessToken?: InputMaybe + /** + * An ordered set of delivery addresses tied to the buyer that is interacting with the cart. + * The rank of the preferences is determined by the order of the addresses in the array. Preferences + * can be used to populate relevant fields in the checkout flow. + * + */ + deliveryAddressPreferences?: InputMaybe> /** The email address of the buyer that is interacting with the cart. */ email?: InputMaybe /** The phone number of the buyer that is interacting with the cart. */ @@ -509,8 +600,8 @@ export type CartCodeDiscountAllocation = CartDiscountAllocation & { /** * The costs that the buyer will pay at checkout. - * It uses [`CartBuyerIdentity`](https://shopify.dev/api/storefront/reference/cart/cartbuyeridentity) to determine - * [international pricing](https://shopify.dev/api/examples/international-pricing#create-a-cart). + * The cart cost uses [`CartBuyerIdentity`](https://shopify.dev/api/storefront/reference/cart/cartbuyeridentity) to determine + * [international pricing](https://shopify.dev/custom-storefronts/internationalization/international-pricing). * */ export type CartCost = { @@ -564,6 +655,8 @@ export type CartDeliveryGroup = { deliveryOptions: Array /** The ID for the delivery group. */ id: Scalars['ID'] + /** The selected delivery option for the delivery group. */ + selectedDeliveryOption?: Maybe } /** Information about the options available for one or more line items to be delivered to a specific address. */ @@ -612,6 +705,8 @@ export type CartDeliveryOption = { description?: Maybe /** The estimated cost for the delivery option. */ estimatedCost: MoneyV2 + /** The unique identifier of the delivery option. */ + handle: Scalars['String'] /** The title of the delivery option. */ title?: Maybe } @@ -656,8 +751,10 @@ export enum CartErrorCode { /** * The estimated costs that the buyer will pay at checkout. - * It uses [`CartBuyerIdentity`](https://shopify.dev/api/storefront/reference/cart/cartbuyeridentity) to determine - * [international pricing](https://shopify.dev/api/examples/international-pricing#create-a-cart). + * The estimated cost uses + * [`CartBuyerIdentity`](https://shopify.dev/api/storefront/reference/cart/cartbuyeridentity) + * to determine + * [international pricing](https://shopify.dev/custom-storefronts/internationalization/international-pricing). * */ export type CartEstimatedCost = { @@ -678,7 +775,12 @@ export type CartEstimatedCost = { export type CartInput = { /** An array of key-value pairs that contains additional information about the cart. */ attributes?: InputMaybe> - /** The customer associated with the cart. Used to determine [international pricing](https://shopify.dev/api/examples/international-pricing#create-a-checkout). Buyer identity should match the customer's shipping address. */ + /** + * The customer associated with the cart. Used to determine [international pricing] + * (https://shopify.dev/custom-storefronts/internationalization/international-pricing). + * Buyer identity should match the customer's shipping address. + * + */ buyerIdentity?: InputMaybe /** * The case-insensitive discount codes that the customer added at checkout. @@ -836,6 +938,26 @@ export type CartNoteUpdatePayload = { userErrors: Array } +/** + * The input fields for updating the selected delivery options for a delivery group. + * + */ +export type CartSelectedDeliveryOptionInput = { + /** The ID of the cart delivery group. */ + deliveryGroupId: Scalars['ID'] + /** The handle of the selected delivery option. */ + deliveryOptionHandle: Scalars['String'] +} + +/** Return type for `cartSelectedDeliveryOptionsUpdate` mutation. */ +export type CartSelectedDeliveryOptionsUpdatePayload = { + __typename?: 'CartSelectedDeliveryOptionsUpdatePayload' + /** The updated cart. */ + cart?: Maybe + /** The list of errors that occurred from executing the mutation. */ + userErrors: Array +} + /** Represents an error that happens during execution of a cart mutation. */ export type CartUserError = DisplayableError & { __typename?: 'CartUserError' @@ -885,12 +1007,12 @@ export type Checkout = Node & { order?: Maybe /** The Order Status Page for this Checkout, null when checkout is not completed. */ orderStatusUrl?: Maybe + /** The amount left to be paid. This is equal to the cost of the line items, taxes, and shipping, minus discounts and gift cards. */ + paymentDue: MoneyV2 /** - * The amount left to be paid. This is equal to the cost of the line items, taxes and shipping minus discounts and gift cards. - * @deprecated Use `paymentDueV2` instead. + * The amount left to be paid. This is equal to the cost of the line items, duties, taxes, and shipping, minus discounts and gift cards. + * @deprecated Use `paymentDue` instead. */ - paymentDue: Scalars['Money'] - /** The amount left to be paid. This is equal to the cost of the line items, duties, taxes, and shipping, minus discounts and gift cards. */ paymentDueV2: MoneyV2 /** * Whether or not the Checkout is ready and can be completed. Checkouts may @@ -911,12 +1033,12 @@ export type Checkout = Node & { shippingDiscountAllocations: Array /** Once a shipping rate is selected by the customer it is transitioned to a `shipping_line` object. */ shippingLine?: Maybe + /** The price at checkout before shipping and taxes. */ + subtotalPrice: MoneyV2 /** - * Price of the checkout before shipping and taxes. - * @deprecated Use `subtotalPriceV2` instead. + * The price at checkout before duties, shipping, and taxes. + * @deprecated Use `subtotalPrice` instead. */ - subtotalPrice: Scalars['Money'] - /** The price at checkout before duties, shipping, and taxes. */ subtotalPriceV2: MoneyV2 /** Whether the checkout is tax exempt. */ taxExempt: Scalars['Boolean'] @@ -924,19 +1046,19 @@ export type Checkout = Node & { taxesIncluded: Scalars['Boolean'] /** The sum of all the duties applied to the line items in the checkout. */ totalDuties?: Maybe + /** The sum of all the prices of all the items in the checkout, including taxes and duties. */ + totalPrice: MoneyV2 /** - * The sum of all the prices of all the items in the checkout, taxes and discounts included. - * @deprecated Use `totalPriceV2` instead. + * The sum of all the prices of all the items in the checkout, including taxes and duties. + * @deprecated Use `totalPrice` instead. */ - totalPrice: Scalars['Money'] - /** The sum of all the prices of all the items in the checkout, including duties, taxes, and discounts. */ totalPriceV2: MoneyV2 + /** The sum of all the taxes applied to the line items and shipping lines in the checkout. */ + totalTax: MoneyV2 /** * The sum of all the taxes applied to the line items and shipping lines in the checkout. - * @deprecated Use `totalTaxV2` instead. + * @deprecated Use `totalTax` instead. */ - totalTax: Scalars['Money'] - /** The sum of all the taxes applied to the line items and shipping lines in the checkout. */ totalTaxV2: MoneyV2 /** The date and time when the checkout was last updated. */ updatedAt: Scalars['DateTime'] @@ -1181,6 +1303,8 @@ export enum CheckoutErrorCode { CustomerAlreadyUsedOncePerCustomerDiscountNotice = 'CUSTOMER_ALREADY_USED_ONCE_PER_CUSTOMER_DISCOUNT_NOTICE', /** Discount already applied. */ DiscountAlreadyApplied = 'DISCOUNT_ALREADY_APPLIED', + /** Discount code isn't working right now. Please contact us for help. */ + DiscountCodeApplicationFailed = 'DISCOUNT_CODE_APPLICATION_FAILED', /** Discount disabled. */ DiscountDisabled = 'DISCOUNT_DISABLED', /** Discount expired. */ @@ -2552,6 +2676,8 @@ export type Customer = HasMetafields & { * */ metafields: Array> + /** The number of orders that the customer has made at the store in their lifetime. */ + numberOfOrders: Scalars['UnsignedInt64'] /** The orders associated with the customer. */ orders: OrderConnection /** The customer’s phone number. */ @@ -2921,6 +3047,18 @@ export type CustomerUserError = DisplayableError & { message: Scalars['String'] } +/** A delivery address of the buyer that is interacting with the cart. */ +export type DeliveryAddress = MailingAddress + +/** + * The input fields for delivery address preferences. + * + */ +export type DeliveryAddressInput = { + /** A delivery address preference of a buyer that is interacting with the cart. */ + deliveryAddress?: InputMaybe +} + /** List of different delivery method types. */ export enum DeliveryMethodType { /** Local Delivery. */ @@ -3125,7 +3263,7 @@ export type Filter = { * The type of data that the filter group represents. * * For more information, refer to [Filter products in a collection with the Storefront API] - * (https://shopify.dev/api/examples/filter-products). + * (https://shopify.dev/custom-storefronts/products-collections/filter-products). * */ export enum FilterType { @@ -4138,6 +4276,8 @@ export type Metafield = Node & { parentResource: MetafieldParentResource /** Returns a reference object if the metafield definition's type is a resource reference. */ reference?: Maybe + /** A list of reference objects if the metafield's type is a resource reference list. */ + references?: Maybe /** * The type name of the metafield. * See the list of [supported types](https://shopify.dev/apps/metafields/definitions/types). @@ -4150,6 +4290,18 @@ export type Metafield = Node & { value: Scalars['String'] } +/** + * Metafields represent custom metadata attached to a resource. Metafields can be sorted into namespaces and are + * comprised of keys, values, and value types. + * + */ +export type MetafieldReferencesArgs = { + after?: InputMaybe + before?: InputMaybe + first?: InputMaybe + last?: InputMaybe +} + /** * A filter used to view a subset of products in a collection matching a specific metafield value. * @@ -4186,13 +4338,128 @@ export type MetafieldParentResource = * */ export type MetafieldReference = + | Collection | GenericFile | MediaImage + | Metaobject | Page | Product | ProductVariant | Video +/** + * An auto-generated type for paginating through multiple MetafieldReferences. + * + */ +export type MetafieldReferenceConnection = { + __typename?: 'MetafieldReferenceConnection' + /** A list of edges. */ + edges: Array + /** A list of the nodes contained in MetafieldReferenceEdge. */ + nodes: Array + /** Information to aid in pagination. */ + pageInfo: PageInfo +} + +/** + * An auto-generated type which holds one MetafieldReference and a cursor during pagination. + * + */ +export type MetafieldReferenceEdge = { + __typename?: 'MetafieldReferenceEdge' + /** A cursor for use in pagination. */ + cursor: Scalars['String'] + /** The item at the end of MetafieldReferenceEdge. */ + node: MetafieldReference +} + +/** An instance of a user-defined model based on a MetaobjectDefinition. */ +export type Metaobject = Node & { + __typename?: 'Metaobject' + /** Accesses a field of the object by key. */ + field?: Maybe + /** + * All object fields with defined values. + * Omitted object keys can be assumed null, and no guarantees are made about field order. + * + */ + fields: Array + /** The unique handle of the metaobject. Useful as a custom ID. */ + handle: Scalars['String'] + /** A globally-unique identifier. */ + id: Scalars['ID'] + /** The type of the metaobject. Defines the namespace of its associated metafields. */ + type: Scalars['String'] + /** The date and time when the metaobject was last updated. */ + updatedAt: Scalars['DateTime'] +} + +/** An instance of a user-defined model based on a MetaobjectDefinition. */ +export type MetaobjectFieldArgs = { + key: Scalars['String'] +} + +/** + * An auto-generated type for paginating through multiple Metaobjects. + * + */ +export type MetaobjectConnection = { + __typename?: 'MetaobjectConnection' + /** A list of edges. */ + edges: Array + /** A list of the nodes contained in MetaobjectEdge. */ + nodes: Array + /** Information to aid in pagination. */ + pageInfo: PageInfo +} + +/** + * An auto-generated type which holds one Metaobject and a cursor during pagination. + * + */ +export type MetaobjectEdge = { + __typename?: 'MetaobjectEdge' + /** A cursor for use in pagination. */ + cursor: Scalars['String'] + /** The item at the end of MetaobjectEdge. */ + node: Metaobject +} + +/** Provides the value of a Metaobject field. */ +export type MetaobjectField = { + __typename?: 'MetaobjectField' + /** The field key. */ + key: Scalars['String'] + /** A referenced object if the field type is a resource reference. */ + reference?: Maybe + /** A list of referenced objects if the field type is a resource reference list. */ + references?: Maybe + /** + * The type name of the field. + * See the list of [supported types](https://shopify.dev/apps/metafields/definitions/types). + * + */ + type: Scalars['String'] + /** The field value. */ + value?: Maybe +} + +/** Provides the value of a Metaobject field. */ +export type MetaobjectFieldReferencesArgs = { + after?: InputMaybe + before?: InputMaybe + first?: InputMaybe + last?: InputMaybe +} + +/** The input fields used to retrieve a metaobject by handle. */ +export type MetaobjectHandleInput = { + /** The handle of the metaobject. */ + handle: Scalars['String'] + /** The type of the metaobject. */ + type: Scalars['String'] +} + /** Represents a Shopify hosted 3D model. */ export type Model3d = Media & Node & { @@ -4250,7 +4517,7 @@ export type Mutation = { /** * Updates customer information associated with a cart. * Buyer identity is used to determine - * [international pricing](https://shopify.dev/api/examples/international-pricing#create-a-checkout) + * [international pricing](https://shopify.dev/custom-storefronts/internationalization/international-pricing) * and should match the customer's shipping address. * */ @@ -4267,6 +4534,8 @@ export type Mutation = { cartLinesUpdate?: Maybe /** Updates the note on the cart. */ cartNoteUpdate?: Maybe + /** Update the selected delivery options for a delivery group. */ + cartSelectedDeliveryOptionsUpdate?: Maybe /** Updates the attributes of a checkout if `allowPartialAddresses` is `true`. */ checkoutAttributesUpdateV2?: Maybe /** Completes a checkout without providing payment information. You can use this mutation for free items or items whose purchase price is covered by a gift card. */ @@ -4342,7 +4611,17 @@ export type Mutation = { /** Updates the default address of an existing customer. */ customerDefaultAddressUpdate?: Maybe /** - * "Sends a reset password email to the customer. The reset password email contains a reset password URL and token that you can pass to the [`customerResetByUrl`](https://shopify.dev/api/storefront/latest/mutations/customerResetByUrl) or [`customerReset`](https://shopify.dev/api/storefront/latest/mutations/customerReset) mutation to reset the customer password." + * Sends a reset password email to the customer. The reset password + * email contains a reset password URL and token that you can pass to + * the [`customerResetByUrl`](https://shopify.dev/api/storefront/latest/mutations/customerResetByUrl) or + * [`customerReset`](https://shopify.dev/api/storefront/latest/mutations/customerReset) mutation to reset the + * customer password. + * + * This mutation is throttled by IP. With authenticated access, + * you can provide a [`Shopify-Storefront-Buyer-IP`](https://shopify.dev/api/usage/authentication#optional-ip-header) instead of the request IP. + * + * Make sure that the value provided to `Shopify-Storefront-Buyer-IP` is trusted. Unthrottled access to this + * mutation presents a security risk. * */ customerRecover?: Maybe @@ -4407,6 +4686,12 @@ export type MutationCartNoteUpdateArgs = { note?: InputMaybe } +/** The schema’s entry-point for mutations. This acts as the public, top-level API from which all mutation queries must start. */ +export type MutationCartSelectedDeliveryOptionsUpdateArgs = { + cartId: Scalars['ID'] + selectedDeliveryOptions: Array +} + /** The schema’s entry-point for mutations. This acts as the public, top-level API from which all mutation queries must start. */ export type MutationCheckoutAttributesUpdateV2Args = { checkoutId: Scalars['ID'] @@ -4633,6 +4918,8 @@ export type Order = HasMetafields & currentTotalPrice: MoneyV2 /** The total of all taxes applied to the order, excluding taxes for returned line items. */ currentTotalTax: MoneyV2 + /** A list of the custom attributes added to the order. */ + customAttributes: Array /** The locale code in which this specific order happened. */ customerLocale?: Maybe /** The unique URL that the customer can use to access the order. */ @@ -4688,42 +4975,42 @@ export type Order = HasMetafields & shippingDiscountAllocations: Array /** The unique URL for the order's status page. */ statusUrl: Scalars['URL'] + /** Price of the order before shipping and taxes. */ + subtotalPrice?: Maybe /** - * Price of the order before shipping and taxes. - * @deprecated Use `subtotalPriceV2` instead. + * Price of the order before duties, shipping and taxes. + * @deprecated Use `subtotalPrice` instead. */ - subtotalPrice?: Maybe - /** Price of the order before duties, shipping and taxes. */ subtotalPriceV2?: Maybe /** List of the order’s successful fulfillments. */ successfulFulfillments?: Maybe> - /** - * The sum of all the prices of all the items in the order, taxes and discounts included (must be positive). - * @deprecated Use `totalPriceV2` instead. - */ - totalPrice: Scalars['Money'] /** The sum of all the prices of all the items in the order, duties, taxes and discounts included (must be positive). */ + totalPrice: MoneyV2 + /** + * The sum of all the prices of all the items in the order, duties, taxes and discounts included (must be positive). + * @deprecated Use `totalPrice` instead. + */ totalPriceV2: MoneyV2 + /** The total amount that has been refunded. */ + totalRefunded: MoneyV2 /** * The total amount that has been refunded. - * @deprecated Use `totalRefundedV2` instead. + * @deprecated Use `totalRefunded` instead. */ - totalRefunded: Scalars['Money'] - /** The total amount that has been refunded. */ totalRefundedV2: MoneyV2 + /** The total cost of shipping. */ + totalShippingPrice: MoneyV2 /** * The total cost of shipping. - * @deprecated Use `totalShippingPriceV2` instead. + * @deprecated Use `totalShippingPrice` instead. */ - totalShippingPrice: Scalars['Money'] - /** The total cost of shipping. */ totalShippingPriceV2: MoneyV2 + /** The total cost of taxes. */ + totalTax?: Maybe /** * The total cost of taxes. - * @deprecated Use `totalTaxV2` instead. + * @deprecated Use `totalTax` instead. */ - totalTax?: Maybe - /** The total cost of taxes. */ totalTaxV2?: Maybe } @@ -4787,6 +5074,8 @@ export type OrderConnection = { nodes: Array /** Information to aid in pagination. */ pageInfo: PageInfo + /** The total count of Orders. */ + totalCount: Scalars['UnsignedInt64'] } /** @@ -5009,12 +5298,12 @@ export enum PageSortKeys { /** A payment applied to a checkout. */ export type Payment = Node & { __typename?: 'Payment' + /** The amount of the payment. */ + amount: MoneyV2 /** * The amount of the payment. - * @deprecated Use `amountV2` instead. + * @deprecated Use `amount` instead. */ - amount: Scalars['Money'] - /** The amount of the payment. */ amountV2: MoneyV2 /** The billing address for the payment. */ billingAddress?: Maybe @@ -5131,6 +5420,8 @@ export type Product = HasMetafields & id: Scalars['ID'] /** List of images associated with the product. */ images: ImageConnection + /** Whether the product is a gift card. */ + isGiftCard: Scalars['Boolean'] /** The media associated with the product. */ media: MediaConnection /** Returns a metafield found by namespace and key. */ @@ -5355,6 +5646,8 @@ export type ProductFilter = { productType?: InputMaybe /** The product vendor to filter on. */ productVendor?: InputMaybe + /** A product tag to filter on. */ + tag?: InputMaybe /** A variant metafield to filter on. */ variantMetafield?: InputMaybe /** A variant option to filter on. */ @@ -5450,12 +5743,12 @@ export type ProductVariant = HasMetafields & availableForSale: Scalars['Boolean'] /** The barcode (for example, ISBN, UPC, or GTIN) associated with the variant. */ barcode?: Maybe + /** The compare at price of the variant. This can be used to mark a variant as on sale, when `compareAtPrice` is higher than `price`. */ + compareAtPrice?: Maybe /** - * The compare at price of the variant. This can be used to mark a variant as on sale, when `compareAtPrice` is higher than `price`. - * @deprecated Use `compareAtPriceV2` instead. + * The compare at price of the variant. This can be used to mark a variant as on sale, when `compareAtPriceV2` is higher than `priceV2`. + * @deprecated Use `compareAtPrice` instead. */ - compareAtPrice?: Maybe - /** The compare at price of the variant. This can be used to mark a variant as on sale, when `compareAtPriceV2` is higher than `priceV2`. */ compareAtPriceV2?: Maybe /** Whether a product is out of stock but still available for purchase (used for backorders). */ currentlyNotInStock: Scalars['Boolean'] @@ -5473,12 +5766,12 @@ export type ProductVariant = HasMetafields & * */ metafields: Array> + /** The product variant’s price. */ + price: MoneyV2 /** * The product variant’s price. - * @deprecated Use `priceV2` instead. + * @deprecated Use `price` instead. */ - price: Scalars['Money'] - /** The product variant’s price. */ priceV2: MoneyV2 /** The product object that the product variant belongs to. */ product: Product @@ -5532,6 +5825,7 @@ export type ProductVariantStoreAvailabilityArgs = { before?: InputMaybe first?: InputMaybe last?: InputMaybe + near?: InputMaybe reverse?: InputMaybe } @@ -5593,7 +5887,11 @@ export type QueryRoot = { blogByHandle?: Maybe /** List of the shop's blogs. */ blogs: BlogConnection - /** Retrieve a cart by its ID. For more information, refer to [Manage a cart with the Storefront API](https://shopify.dev/api/examples/cart). */ + /** + * Retrieve a cart by its ID. For more information, refer to + * [Manage a cart with the Storefront API](https://shopify.dev/custom-storefronts/cart/manage). + * + */ cart?: Maybe /** Fetch a specific `Collection` by one of its unique attributes. */ collection?: Maybe @@ -5617,6 +5915,10 @@ export type QueryRoot = { locations: LocationConnection /** A storefront menu. */ menu?: Maybe + /** Fetch a specific Metaobject by one of its unique identifiers. */ + metaobject?: Maybe + /** All active metaobjects for the shop. */ + metaobjects: MetaobjectConnection /** Returns a specific node by ID. */ node?: Maybe /** Returns the list of nodes with the given IDs. */ @@ -5743,6 +6045,23 @@ export type QueryRootMenuArgs = { handle: Scalars['String'] } +/** The schema’s entry-point for queries. This acts as the public, top-level API from which all queries must start. */ +export type QueryRootMetaobjectArgs = { + handle?: InputMaybe + id?: InputMaybe +} + +/** The schema’s entry-point for queries. This acts as the public, top-level API from which all queries must start. */ +export type QueryRootMetaobjectsArgs = { + after?: InputMaybe + before?: InputMaybe + first?: InputMaybe + last?: InputMaybe + reverse?: InputMaybe + sortKey?: InputMaybe + type: Scalars['String'] +} + /** The schema’s entry-point for queries. This acts as the public, top-level API from which all queries must start. */ export type QueryRootNodeArgs = { id: Scalars['ID'] @@ -5818,6 +6137,7 @@ export type QueryRootUrlRedirectsArgs = { before?: InputMaybe first?: InputMaybe last?: InputMaybe + query?: InputMaybe reverse?: InputMaybe } @@ -6107,12 +6427,12 @@ export type ShippingRate = { __typename?: 'ShippingRate' /** Human-readable unique identifier for this shipping rate. */ handle: Scalars['String'] + /** Price of this shipping rate. */ + price: MoneyV2 /** * Price of this shipping rate. - * @deprecated Use `priceV2` instead. + * @deprecated Use `price` instead. */ - price: Scalars['Money'] - /** Price of this shipping rate. */ priceV2: MoneyV2 /** Title of this shipping rate. */ title: Scalars['String'] @@ -6122,6 +6442,8 @@ export type ShippingRate = { export type Shop = HasMetafields & Node & { __typename?: 'Shop' + /** The shop's branding configuration. */ + brand?: Maybe /** A description of the shop. */ description?: Maybe /** A globally-unique identifier. */ @@ -6291,12 +6613,12 @@ export type TokenizedPaymentInputV3 = { /** An object representing exchange of money for a product or service. */ export type Transaction = { __typename?: 'Transaction' + /** The amount of money that the transaction was for. */ + amount: MoneyV2 /** * The amount of money that the transaction was for. - * @deprecated Use `amountV2` instead. + * @deprecated Use `amount` instead. */ - amount: Scalars['Money'] - /** The amount of money that the transaction was for. */ amountV2: MoneyV2 /** The kind of the transaction. */ kind: TransactionKind @@ -6502,6 +6824,94 @@ export enum WeightUnit { Pounds = 'POUNDS', } +export type CartDetailsFragment = { + __typename?: 'Cart' + id: string + checkoutUrl: any + createdAt: any + updatedAt: any + lines: { + __typename?: 'CartLineConnection' + edges: Array<{ + __typename?: 'CartLineEdge' + node: { + __typename?: 'CartLine' + id: string + quantity: number + merchandise: { + __typename?: 'ProductVariant' + id: string + sku?: string | null + title: string + selectedOptions: Array<{ + __typename?: 'SelectedOption' + name: string + value: string + }> + image?: { + __typename?: 'Image' + url: any + altText?: string | null + width?: number | null + height?: number | null + } | null + price: { + __typename?: 'MoneyV2' + amount: any + currencyCode: CurrencyCode + } + compareAtPrice?: { + __typename?: 'MoneyV2' + amount: any + currencyCode: CurrencyCode + } | null + product: { __typename?: 'Product'; title: string; handle: string } + } + } + }> + } + attributes: Array<{ + __typename?: 'Attribute' + key: string + value?: string | null + }> + buyerIdentity: { + __typename?: 'CartBuyerIdentity' + email?: string | null + customer?: { __typename?: 'Customer'; id: string } | null + } + estimatedCost: { + __typename?: 'CartEstimatedCost' + totalAmount: { + __typename?: 'MoneyV2' + amount: any + currencyCode: CurrencyCode + } + subtotalAmount: { + __typename?: 'MoneyV2' + amount: any + currencyCode: CurrencyCode + } + totalTaxAmount?: { + __typename?: 'MoneyV2' + amount: any + currencyCode: CurrencyCode + } | null + totalDutyAmount?: { + __typename?: 'MoneyV2' + amount: any + currencyCode: CurrencyCode + } | null + } +} + +export type UserErrorsFragment = { + __typename?: 'CartUserError' + code?: CartErrorCode | null + field?: Array | null + message: string +} + export type AssociateCustomerWithCheckoutMutationVariables = Exact<{ checkoutId: Scalars['ID'] customerAccessToken: Scalars['String'] @@ -6522,57 +6932,29 @@ export type AssociateCustomerWithCheckoutMutation = { } | null } -export type CheckoutCreateMutationVariables = Exact<{ - input?: InputMaybe +export type CartCreateMutationVariables = Exact<{ + input?: InputMaybe }> -export type CheckoutCreateMutation = { +export type CartCreateMutation = { __typename?: 'Mutation' - checkoutCreate?: { - __typename?: 'CheckoutCreatePayload' - checkoutUserErrors: Array<{ - __typename?: 'CheckoutUserError' - code?: CheckoutErrorCode | null - field?: Array | null - message: string - }> - checkout?: { - __typename?: 'Checkout' + cartCreate?: { + __typename?: 'CartCreatePayload' + cart?: { + __typename?: 'Cart' id: string - webUrl: any - completedAt?: any | null + checkoutUrl: any createdAt: any - taxesIncluded: boolean - subtotalPriceV2: { - __typename?: 'MoneyV2' - amount: any - currencyCode: CurrencyCode - } - totalTaxV2: { - __typename?: 'MoneyV2' - amount: any - currencyCode: CurrencyCode - } - totalPriceV2: { - __typename?: 'MoneyV2' - amount: any - currencyCode: CurrencyCode - } - lineItems: { - __typename?: 'CheckoutLineItemConnection' - pageInfo: { - __typename?: 'PageInfo' - hasNextPage: boolean - hasPreviousPage: boolean - } + updatedAt: any + lines: { + __typename?: 'CartLineConnection' edges: Array<{ - __typename?: 'CheckoutLineItemEdge' + __typename?: 'CartLineEdge' node: { - __typename?: 'CheckoutLineItem' + __typename?: 'CartLine' id: string - title: string quantity: number - variant?: { + merchandise: { __typename?: 'ProductVariant' id: string sku?: string | null @@ -6584,82 +6966,93 @@ export type CheckoutCreateMutation = { }> image?: { __typename?: 'Image' - originalSrc: any + url: any altText?: string | null width?: number | null height?: number | null } | null - priceV2: { + price: { __typename?: 'MoneyV2' amount: any currencyCode: CurrencyCode } - compareAtPriceV2?: { + compareAtPrice?: { __typename?: 'MoneyV2' amount: any currencyCode: CurrencyCode } | null - product: { __typename?: 'Product'; handle: string } - } | null + product: { __typename?: 'Product'; title: string; handle: string } + } } }> } + attributes: Array<{ + __typename?: 'Attribute' + key: string + value?: string | null + }> + buyerIdentity: { + __typename?: 'CartBuyerIdentity' + email?: string | null + customer?: { __typename?: 'Customer'; id: string } | null + } + estimatedCost: { + __typename?: 'CartEstimatedCost' + totalAmount: { + __typename?: 'MoneyV2' + amount: any + currencyCode: CurrencyCode + } + subtotalAmount: { + __typename?: 'MoneyV2' + amount: any + currencyCode: CurrencyCode + } + totalTaxAmount?: { + __typename?: 'MoneyV2' + amount: any + currencyCode: CurrencyCode + } | null + totalDutyAmount?: { + __typename?: 'MoneyV2' + amount: any + currencyCode: CurrencyCode + } | null + } } | null + userErrors: Array<{ + __typename?: 'CartUserError' + code?: CartErrorCode | null + field?: Array | null + message: string + }> } | null } -export type CheckoutLineItemAddMutationVariables = Exact<{ - checkoutId: Scalars['ID'] - lineItems: Array | CheckoutLineItemInput +export type CartLinesAddMutationVariables = Exact<{ + lines: Array | CartLineInput + cartId: Scalars['ID'] }> -export type CheckoutLineItemAddMutation = { +export type CartLinesAddMutation = { __typename?: 'Mutation' - checkoutLineItemsAdd?: { - __typename?: 'CheckoutLineItemsAddPayload' - checkoutUserErrors: Array<{ - __typename?: 'CheckoutUserError' - code?: CheckoutErrorCode | null - field?: Array | null - message: string - }> - checkout?: { - __typename?: 'Checkout' + cartLinesAdd?: { + __typename?: 'CartLinesAddPayload' + cart?: { + __typename?: 'Cart' id: string - webUrl: any - completedAt?: any | null + checkoutUrl: any createdAt: any - taxesIncluded: boolean - subtotalPriceV2: { - __typename?: 'MoneyV2' - amount: any - currencyCode: CurrencyCode - } - totalTaxV2: { - __typename?: 'MoneyV2' - amount: any - currencyCode: CurrencyCode - } - totalPriceV2: { - __typename?: 'MoneyV2' - amount: any - currencyCode: CurrencyCode - } - lineItems: { - __typename?: 'CheckoutLineItemConnection' - pageInfo: { - __typename?: 'PageInfo' - hasNextPage: boolean - hasPreviousPage: boolean - } + updatedAt: any + lines: { + __typename?: 'CartLineConnection' edges: Array<{ - __typename?: 'CheckoutLineItemEdge' + __typename?: 'CartLineEdge' node: { - __typename?: 'CheckoutLineItem' + __typename?: 'CartLine' id: string - title: string quantity: number - variant?: { + merchandise: { __typename?: 'ProductVariant' id: string sku?: string | null @@ -6671,82 +7064,93 @@ export type CheckoutLineItemAddMutation = { }> image?: { __typename?: 'Image' - originalSrc: any + url: any altText?: string | null width?: number | null height?: number | null } | null - priceV2: { + price: { __typename?: 'MoneyV2' amount: any currencyCode: CurrencyCode } - compareAtPriceV2?: { + compareAtPrice?: { __typename?: 'MoneyV2' amount: any currencyCode: CurrencyCode } | null - product: { __typename?: 'Product'; handle: string } - } | null + product: { __typename?: 'Product'; title: string; handle: string } + } } }> } + attributes: Array<{ + __typename?: 'Attribute' + key: string + value?: string | null + }> + buyerIdentity: { + __typename?: 'CartBuyerIdentity' + email?: string | null + customer?: { __typename?: 'Customer'; id: string } | null + } + estimatedCost: { + __typename?: 'CartEstimatedCost' + totalAmount: { + __typename?: 'MoneyV2' + amount: any + currencyCode: CurrencyCode + } + subtotalAmount: { + __typename?: 'MoneyV2' + amount: any + currencyCode: CurrencyCode + } + totalTaxAmount?: { + __typename?: 'MoneyV2' + amount: any + currencyCode: CurrencyCode + } | null + totalDutyAmount?: { + __typename?: 'MoneyV2' + amount: any + currencyCode: CurrencyCode + } | null + } } | null + userErrors: Array<{ + __typename?: 'CartUserError' + code?: CartErrorCode | null + field?: Array | null + message: string + }> } | null } -export type CheckoutLineItemRemoveMutationVariables = Exact<{ - checkoutId: Scalars['ID'] - lineItemIds: Array | Scalars['ID'] +export type CartLinesRemoveMutationVariables = Exact<{ + cartId: Scalars['ID'] + lineIds: Array | Scalars['ID'] }> -export type CheckoutLineItemRemoveMutation = { +export type CartLinesRemoveMutation = { __typename?: 'Mutation' - checkoutLineItemsRemove?: { - __typename?: 'CheckoutLineItemsRemovePayload' - checkoutUserErrors: Array<{ - __typename?: 'CheckoutUserError' - code?: CheckoutErrorCode | null - field?: Array | null - message: string - }> - checkout?: { - __typename?: 'Checkout' + cartLinesRemove?: { + __typename?: 'CartLinesRemovePayload' + cart?: { + __typename?: 'Cart' id: string - webUrl: any - completedAt?: any | null + checkoutUrl: any createdAt: any - taxesIncluded: boolean - subtotalPriceV2: { - __typename?: 'MoneyV2' - amount: any - currencyCode: CurrencyCode - } - totalTaxV2: { - __typename?: 'MoneyV2' - amount: any - currencyCode: CurrencyCode - } - totalPriceV2: { - __typename?: 'MoneyV2' - amount: any - currencyCode: CurrencyCode - } - lineItems: { - __typename?: 'CheckoutLineItemConnection' - pageInfo: { - __typename?: 'PageInfo' - hasNextPage: boolean - hasPreviousPage: boolean - } + updatedAt: any + lines: { + __typename?: 'CartLineConnection' edges: Array<{ - __typename?: 'CheckoutLineItemEdge' + __typename?: 'CartLineEdge' node: { - __typename?: 'CheckoutLineItem' + __typename?: 'CartLine' id: string - title: string quantity: number - variant?: { + merchandise: { __typename?: 'ProductVariant' id: string sku?: string | null @@ -6758,82 +7162,93 @@ export type CheckoutLineItemRemoveMutation = { }> image?: { __typename?: 'Image' - originalSrc: any + url: any altText?: string | null width?: number | null height?: number | null } | null - priceV2: { + price: { __typename?: 'MoneyV2' amount: any currencyCode: CurrencyCode } - compareAtPriceV2?: { + compareAtPrice?: { __typename?: 'MoneyV2' amount: any currencyCode: CurrencyCode } | null - product: { __typename?: 'Product'; handle: string } - } | null + product: { __typename?: 'Product'; title: string; handle: string } + } } }> } + attributes: Array<{ + __typename?: 'Attribute' + key: string + value?: string | null + }> + buyerIdentity: { + __typename?: 'CartBuyerIdentity' + email?: string | null + customer?: { __typename?: 'Customer'; id: string } | null + } + estimatedCost: { + __typename?: 'CartEstimatedCost' + totalAmount: { + __typename?: 'MoneyV2' + amount: any + currencyCode: CurrencyCode + } + subtotalAmount: { + __typename?: 'MoneyV2' + amount: any + currencyCode: CurrencyCode + } + totalTaxAmount?: { + __typename?: 'MoneyV2' + amount: any + currencyCode: CurrencyCode + } | null + totalDutyAmount?: { + __typename?: 'MoneyV2' + amount: any + currencyCode: CurrencyCode + } | null + } } | null + userErrors: Array<{ + __typename?: 'CartUserError' + code?: CartErrorCode | null + field?: Array | null + message: string + }> } | null } -export type CheckoutLineItemUpdateMutationVariables = Exact<{ - checkoutId: Scalars['ID'] - lineItems: Array | CheckoutLineItemUpdateInput +export type CartLinesUpdateMutationVariables = Exact<{ + cartId: Scalars['ID'] + lines: Array | CartLineUpdateInput }> -export type CheckoutLineItemUpdateMutation = { +export type CartLinesUpdateMutation = { __typename?: 'Mutation' - checkoutLineItemsUpdate?: { - __typename?: 'CheckoutLineItemsUpdatePayload' - checkoutUserErrors: Array<{ - __typename?: 'CheckoutUserError' - code?: CheckoutErrorCode | null - field?: Array | null - message: string - }> - checkout?: { - __typename?: 'Checkout' + cartLinesUpdate?: { + __typename?: 'CartLinesUpdatePayload' + cart?: { + __typename?: 'Cart' id: string - webUrl: any - completedAt?: any | null + checkoutUrl: any createdAt: any - taxesIncluded: boolean - subtotalPriceV2: { - __typename?: 'MoneyV2' - amount: any - currencyCode: CurrencyCode - } - totalTaxV2: { - __typename?: 'MoneyV2' - amount: any - currencyCode: CurrencyCode - } - totalPriceV2: { - __typename?: 'MoneyV2' - amount: any - currencyCode: CurrencyCode - } - lineItems: { - __typename?: 'CheckoutLineItemConnection' - pageInfo: { - __typename?: 'PageInfo' - hasNextPage: boolean - hasPreviousPage: boolean - } + updatedAt: any + lines: { + __typename?: 'CartLineConnection' edges: Array<{ - __typename?: 'CheckoutLineItemEdge' + __typename?: 'CartLineEdge' node: { - __typename?: 'CheckoutLineItem' + __typename?: 'CartLine' id: string - title: string quantity: number - variant?: { + merchandise: { __typename?: 'ProductVariant' id: string sku?: string | null @@ -6845,27 +7260,66 @@ export type CheckoutLineItemUpdateMutation = { }> image?: { __typename?: 'Image' - originalSrc: any + url: any altText?: string | null width?: number | null height?: number | null } | null - priceV2: { + price: { __typename?: 'MoneyV2' amount: any currencyCode: CurrencyCode } - compareAtPriceV2?: { + compareAtPrice?: { __typename?: 'MoneyV2' amount: any currencyCode: CurrencyCode } | null - product: { __typename?: 'Product'; handle: string } - } | null + product: { __typename?: 'Product'; title: string; handle: string } + } } }> } + attributes: Array<{ + __typename?: 'Attribute' + key: string + value?: string | null + }> + buyerIdentity: { + __typename?: 'CartBuyerIdentity' + email?: string | null + customer?: { __typename?: 'Customer'; id: string } | null + } + estimatedCost: { + __typename?: 'CartEstimatedCost' + totalAmount: { + __typename?: 'MoneyV2' + amount: any + currencyCode: CurrencyCode + } + subtotalAmount: { + __typename?: 'MoneyV2' + amount: any + currencyCode: CurrencyCode + } + totalTaxAmount?: { + __typename?: 'MoneyV2' + amount: any + currencyCode: CurrencyCode + } | null + totalDutyAmount?: { + __typename?: 'MoneyV2' + amount: any + currencyCode: CurrencyCode + } | null + } } | null + userErrors: Array<{ + __typename?: 'CartUserError' + code?: CartErrorCode | null + field?: Array | null + message: string + }> } | null } @@ -7088,7 +7542,7 @@ export type ProductConnectionFragment = { __typename?: 'ImageEdge' node: { __typename?: 'Image' - originalSrc: any + url: any altText?: string | null width?: number | null height?: number | null @@ -7142,7 +7596,7 @@ export type GetAllProductsQuery = { __typename?: 'ImageEdge' node: { __typename?: 'Image' - originalSrc: any + url: any altText?: string | null width?: number | null height?: number | null @@ -7154,180 +7608,92 @@ export type GetAllProductsQuery = { } } -export type CheckoutDetailsFragment = { - __typename?: 'Checkout' - id: string - webUrl: any - completedAt?: any | null - createdAt: any - taxesIncluded: boolean - subtotalPriceV2: { - __typename?: 'MoneyV2' - amount: any - currencyCode: CurrencyCode - } - totalTaxV2: { - __typename?: 'MoneyV2' - amount: any - currencyCode: CurrencyCode - } - totalPriceV2: { - __typename?: 'MoneyV2' - amount: any - currencyCode: CurrencyCode - } - lineItems: { - __typename?: 'CheckoutLineItemConnection' - pageInfo: { - __typename?: 'PageInfo' - hasNextPage: boolean - hasPreviousPage: boolean - } - edges: Array<{ - __typename?: 'CheckoutLineItemEdge' - node: { - __typename?: 'CheckoutLineItem' - id: string - title: string - quantity: number - variant?: { - __typename?: 'ProductVariant' - id: string - sku?: string | null - title: string - selectedOptions: Array<{ - __typename?: 'SelectedOption' - name: string - value: string - }> - image?: { - __typename?: 'Image' - originalSrc: any - altText?: string | null - width?: number | null - height?: number | null - } | null - priceV2: { - __typename?: 'MoneyV2' - amount: any - currencyCode: CurrencyCode - } - compareAtPriceV2?: { - __typename?: 'MoneyV2' - amount: any - currencyCode: CurrencyCode - } | null - product: { __typename?: 'Product'; handle: string } - } | null - } - }> - } -} - -export type GetCheckoutQueryVariables = Exact<{ - checkoutId: Scalars['ID'] +export type GetCartQueryVariables = Exact<{ + cartId: Scalars['ID'] }> -export type GetCheckoutQuery = { +export type GetCartQuery = { __typename?: 'QueryRoot' - node?: - | { __typename?: 'AppliedGiftCard' } - | { __typename?: 'Article' } - | { __typename?: 'Blog' } - | { __typename?: 'Cart' } - | { __typename?: 'CartLine' } - | { - __typename?: 'Checkout' - id: string - webUrl: any - completedAt?: any | null - createdAt: any - taxesIncluded: boolean - subtotalPriceV2: { - __typename?: 'MoneyV2' - amount: any - currencyCode: CurrencyCode - } - totalTaxV2: { - __typename?: 'MoneyV2' - amount: any - currencyCode: CurrencyCode - } - totalPriceV2: { - __typename?: 'MoneyV2' - amount: any - currencyCode: CurrencyCode - } - lineItems: { - __typename?: 'CheckoutLineItemConnection' - pageInfo: { - __typename?: 'PageInfo' - hasNextPage: boolean - hasPreviousPage: boolean - } - edges: Array<{ - __typename?: 'CheckoutLineItemEdge' - node: { - __typename?: 'CheckoutLineItem' - id: string - title: string - quantity: number - variant?: { - __typename?: 'ProductVariant' - id: string - sku?: string | null - title: string - selectedOptions: Array<{ - __typename?: 'SelectedOption' - name: string - value: string - }> - image?: { - __typename?: 'Image' - originalSrc: any - altText?: string | null - width?: number | null - height?: number | null - } | null - priceV2: { - __typename?: 'MoneyV2' - amount: any - currencyCode: CurrencyCode - } - compareAtPriceV2?: { - __typename?: 'MoneyV2' - amount: any - currencyCode: CurrencyCode - } | null - product: { __typename?: 'Product'; handle: string } - } | null + cart?: { + __typename?: 'Cart' + id: string + checkoutUrl: any + createdAt: any + updatedAt: any + lines: { + __typename?: 'CartLineConnection' + edges: Array<{ + __typename?: 'CartLineEdge' + node: { + __typename?: 'CartLine' + id: string + quantity: number + merchandise: { + __typename?: 'ProductVariant' + id: string + sku?: string | null + title: string + selectedOptions: Array<{ + __typename?: 'SelectedOption' + name: string + value: string + }> + image?: { + __typename?: 'Image' + url: any + altText?: string | null + width?: number | null + height?: number | null + } | null + price: { + __typename?: 'MoneyV2' + amount: any + currencyCode: CurrencyCode } - }> + compareAtPrice?: { + __typename?: 'MoneyV2' + amount: any + currencyCode: CurrencyCode + } | null + product: { __typename?: 'Product'; title: string; handle: string } + } } + }> + } + attributes: Array<{ + __typename?: 'Attribute' + key: string + value?: string | null + }> + buyerIdentity: { + __typename?: 'CartBuyerIdentity' + email?: string | null + customer?: { __typename?: 'Customer'; id: string } | null + } + estimatedCost: { + __typename?: 'CartEstimatedCost' + totalAmount: { + __typename?: 'MoneyV2' + amount: any + currencyCode: CurrencyCode } - | { __typename?: 'CheckoutLineItem' } - | { __typename?: 'Collection' } - | { __typename?: 'Comment' } - | { __typename?: 'ExternalVideo' } - | { __typename?: 'GenericFile' } - | { __typename?: 'Location' } - | { __typename?: 'MailingAddress' } - | { __typename?: 'MediaImage' } - | { __typename?: 'Menu' } - | { __typename?: 'MenuItem' } - | { __typename?: 'Metafield' } - | { __typename?: 'Model3d' } - | { __typename?: 'Order' } - | { __typename?: 'Page' } - | { __typename?: 'Payment' } - | { __typename?: 'Product' } - | { __typename?: 'ProductOption' } - | { __typename?: 'ProductVariant' } - | { __typename?: 'Shop' } - | { __typename?: 'ShopPolicy' } - | { __typename?: 'UrlRedirect' } - | { __typename?: 'Video' } - | null + subtotalAmount: { + __typename?: 'MoneyV2' + amount: any + currencyCode: CurrencyCode + } + totalTaxAmount?: { + __typename?: 'MoneyV2' + amount: any + currencyCode: CurrencyCode + } | null + totalDutyAmount?: { + __typename?: 'MoneyV2' + amount: any + currencyCode: CurrencyCode + } | null + } + } | null } export type GetProductsFromCollectionQueryVariables = Exact<{ @@ -7384,7 +7750,7 @@ export type GetProductsFromCollectionQuery = { __typename?: 'ImageEdge' node: { __typename?: 'Image' - originalSrc: any + url: any altText?: string | null width?: number | null height?: number | null @@ -7404,6 +7770,7 @@ export type GetProductsFromCollectionQuery = { | { __typename?: 'Menu'; id: string } | { __typename?: 'MenuItem'; id: string } | { __typename?: 'Metafield'; id: string } + | { __typename?: 'Metaobject'; id: string } | { __typename?: 'Model3d'; id: string } | { __typename?: 'Order'; id: string } | { __typename?: 'Page'; id: string } @@ -7471,6 +7838,7 @@ export type GetPageQuery = { | { __typename?: 'Menu'; id: string } | { __typename?: 'MenuItem'; id: string } | { __typename?: 'Metafield'; id: string } + | { __typename?: 'Metaobject'; id: string } | { __typename?: 'Model3d'; id: string } | { __typename?: 'Order'; id: string } | { @@ -7548,12 +7916,12 @@ export type GetProductBySlugQuery = { name: string value: string }> - priceV2: { + price: { __typename?: 'MoneyV2' amount: any currencyCode: CurrencyCode } - compareAtPriceV2?: { + compareAtPrice?: { __typename?: 'MoneyV2' amount: any currencyCode: CurrencyCode @@ -7572,7 +7940,7 @@ export type GetProductBySlugQuery = { __typename?: 'ImageEdge' node: { __typename?: 'Image' - originalSrc: any + url: any altText?: string | null width?: number | null height?: number | null diff --git a/packages/shopify/schema.graphql b/packages/shopify/schema.graphql index d2e600fb9..f8086a92f 100644 --- a/packages/shopify/schema.graphql +++ b/packages/shopify/schema.graphql @@ -14,7 +14,7 @@ directive @accessRestricted( ) on FIELD_DEFINITION | OBJECT """ -Contextualizes data based on the additional information provided by the directive. For example, you can use the `@inContext(country: CA)` directive to [query a product's price](https://shopify.dev/api/examples/international-pricing#query-product-prices) in a storefront within the context of Canada. +Contextualizes data based on the additional information provided by the directive. For example, you can use the `@inContext(country: CA)` directive to [query a product's price](https://shopify.dev/custom-storefronts/internationalization/international-pricing) in a storefront within the context of Canada. """ directive @inContext( """ @@ -58,22 +58,22 @@ type AppliedGiftCard implements Node { """ The amount that was taken from the gift card by applying it. """ - amountUsed: Money! @deprecated(reason: "Use `amountUsedV2` instead.") + amountUsed: MoneyV2! """ The amount that was taken from the gift card by applying it. """ - amountUsedV2: MoneyV2! + amountUsedV2: MoneyV2! @deprecated(reason: "Use `amountUsed` instead.") """ The amount left on the gift card. """ - balance: Money! @deprecated(reason: "Use `balanceV2` instead.") + balance: MoneyV2! """ The amount left on the gift card. """ - balanceV2: MoneyV2! + balanceV2: MoneyV2! @deprecated(reason: "Use `balance` instead.") """ A globally-unique identifier. @@ -560,6 +560,65 @@ enum BlogSortKeys { TITLE } +"The store's branding configuration.\n" +type Brand { + """ + The colors of the store's brand. + """ + colors: BrandColors! + + """ + The store's cover image. + """ + coverImage: MediaImage + + """ + The store's default logo. + """ + logo: MediaImage + + """ + The store's short description. + """ + shortDescription: String + + """ + The store's slogan. + """ + slogan: String + + """ + The store's preferred logo for square UI elements. + """ + squareLogo: MediaImage +} + +"A group of related colors for the shop's brand.\n" +type BrandColorGroup { + """ + The background color. + """ + background: Color + + """ + The foreground color. + """ + foreground: Color +} + +"The colors of the shop's brand.\n" +type BrandColors { + """ + The shop's primary brand colors. + """ + primary: [BrandColorGroup!]! + + """ + The shop's secondary brand colors. + """ + secondary: [BrandColorGroup!]! +} + """ Card brand, such as Visa or Mastercard, which can be used for payments. """ @@ -595,9 +654,7 @@ enum CardBrand { VISA } -""" -A cart represents the merchandise that a buyer intends to purchase, and the estimated cost associated with the cart. To learn how to interact with a cart during a customer's session, refer to [Manage a cart with the Storefront API](https://shopify.dev/api/examples/cart). -""" +"A cart represents the merchandise that a buyer intends to purchase,\nand the estimated cost associated with the cart. Learn how to\n[interact with a cart](https://shopify.dev/custom-storefronts/internationalization/international-pricing)\nduring a customer's session.\n" type Cart implements Node { """ An attribute associated with the cart. @@ -625,7 +682,7 @@ type Cart implements Node { checkoutUrl: URL! """ - The estimated costs that the buyer will pay at checkout. The costs are subject to change and changes will be reflected at checkout. The `cost` field uses the `buyerIdentity` field to determine [international pricing](https://shopify.dev/api/examples/international-pricing#create-a-cart). + The estimated costs that the buyer will pay at checkout. The costs are subject to change and changes will be reflected at checkout. The `cost` field uses the `buyerIdentity` field to determine [international pricing](https://shopify.dev/custom-storefronts/internationalization/international-pricing). """ cost: CartCost! @@ -634,9 +691,7 @@ type Cart implements Node { """ createdAt: DateTime! - """ - The delivery groups available for the cart, based on the default address of the logged-in customer. - """ + "The delivery groups available for the cart, based on the buyer identity default\ndelivery address preference or the default address of the logged-in customer.\n" deliveryGroups( """ Returns the elements that come after the specified cursor. @@ -672,9 +727,7 @@ type Cart implements Node { "The case-insensitive discount codes that the customer added at checkout.\n" discountCodes: [CartDiscountCode!]! - """ - The estimated costs that the buyer will pay at checkout. The estimated costs are subject to change and changes will be reflected at checkout. The `estimatedCost` field uses the `buyerIdentity` field to determine [international pricing](https://shopify.dev/api/examples/international-pricing#create-a-cart). - """ + "The estimated costs that the buyer will pay at checkout.\nThe estimated costs are subject to change and changes will be reflected at checkout.\nThe `estimatedCost` field uses the `buyerIdentity` field to determine\n[international pricing](https://shopify.dev/custom-storefronts/internationalization/international-pricing).\n" estimatedCost: CartEstimatedCost! @deprecated(reason: "Use `cost` instead.") """ @@ -772,6 +825,9 @@ type CartBuyerIdentity { """ customer: Customer + "An ordered set of delivery addresses tied to the buyer that is interacting with the cart.\nThe rank of the preferences is determined by the order of the addresses in the array. Preferences\ncan be used to populate relevant fields in the checkout flow.\n" + deliveryAddressPreferences: [DeliveryAddress!]! + """ The email address of the buyer that is interacting with the cart. """ @@ -783,7 +839,7 @@ type CartBuyerIdentity { phone: String } -"Specifies the input fields to update the buyer information associated with a cart.\nBuyer identity is used to determine\n[international pricing](https://shopify.dev/api/examples/international-pricing#create-a-checkout)\nand should match the customer's shipping address.\n" +"Specifies the input fields to update the buyer information associated with a cart.\nBuyer identity is used to determine\n[international pricing](https://shopify.dev/custom-storefronts/internationalization/international-pricing)\nand should match the customer's shipping address.\n" input CartBuyerIdentityInput { """ The country where the buyer is located. @@ -795,6 +851,9 @@ input CartBuyerIdentityInput { """ customerAccessToken: String + "An ordered set of delivery addresses tied to the buyer that is interacting with the cart.\nThe rank of the preferences is determined by the order of the addresses in the array. Preferences\ncan be used to populate relevant fields in the checkout flow.\n" + deliveryAddressPreferences: [DeliveryAddressInput!] + """ The email address of the buyer that is interacting with the cart. """ @@ -836,7 +895,7 @@ type CartCodeDiscountAllocation implements CartDiscountAllocation { discountedAmount: MoneyV2! } -"The costs that the buyer will pay at checkout.\nIt uses [`CartBuyerIdentity`](https://shopify.dev/api/storefront/reference/cart/cartbuyeridentity) to determine\n[international pricing](https://shopify.dev/api/examples/international-pricing#create-a-cart).\n" +"The costs that the buyer will pay at checkout.\nThe cart cost uses [`CartBuyerIdentity`](https://shopify.dev/api/storefront/reference/cart/cartbuyeridentity) to determine\n[international pricing](https://shopify.dev/custom-storefronts/internationalization/international-pricing).\n" type CartCost { """ The estimated amount, before taxes and discounts, for the customer to pay at checkout. The checkout charge amount doesn't include any deferred payments that'll be paid at a later date. If the cart has no deferred payments, then the checkout charge amount is equivalent to `subtotalAmount`. @@ -962,6 +1021,11 @@ type CartDeliveryGroup { The ID for the delivery group. """ id: ID! + + """ + The selected delivery option for the delivery group. + """ + selectedDeliveryOption: CartDeliveryOption } "An auto-generated type for paginating through multiple CartDeliveryGroups.\n" @@ -1019,6 +1083,11 @@ type CartDeliveryOption { """ estimatedCost: MoneyV2! + """ + The unique identifier of the delivery option. + """ + handle: String! + """ The title of the delivery option. """ @@ -1095,7 +1164,7 @@ enum CartErrorCode { MISSING_NOTE } -"The estimated costs that the buyer will pay at checkout.\nIt uses [`CartBuyerIdentity`](https://shopify.dev/api/storefront/reference/cart/cartbuyeridentity) to determine\n[international pricing](https://shopify.dev/api/examples/international-pricing#create-a-cart).\n" +"The estimated costs that the buyer will pay at checkout.\nThe estimated cost uses\n[`CartBuyerIdentity`](https://shopify.dev/api/storefront/reference/cart/cartbuyeridentity)\nto determine\n[international pricing](https://shopify.dev/custom-storefronts/internationalization/international-pricing).\n" type CartEstimatedCost { """ The estimated amount, before taxes and discounts, for the customer to pay at checkout. The checkout charge amount doesn't include any deferred payments that'll be paid at a later date. If the cart has no deferred payments, then the checkout charge amount is equivalent to`subtotal_amount`. @@ -1132,9 +1201,7 @@ input CartInput { """ attributes: [AttributeInput!] - """ - The customer associated with the cart. Used to determine [international pricing](https://shopify.dev/api/examples/international-pricing#create-a-checkout). Buyer identity should match the customer's shipping address. - """ + "The customer associated with the cart. Used to determine [international pricing]\n(https://shopify.dev/custom-storefronts/internationalization/international-pricing).\nBuyer identity should match the customer's shipping address.\n" buyerIdentity: CartBuyerIdentityInput "The case-insensitive discount codes that the customer added at checkout.\n" @@ -1403,6 +1470,34 @@ type CartNoteUpdatePayload { userErrors: [CartUserError!]! } +"The input fields for updating the selected delivery options for a delivery group.\n" +input CartSelectedDeliveryOptionInput { + """ + The ID of the cart delivery group. + """ + deliveryGroupId: ID! + + """ + The handle of the selected delivery option. + """ + deliveryOptionHandle: String! +} + +""" +Return type for `cartSelectedDeliveryOptionsUpdate` mutation. +""" +type CartSelectedDeliveryOptionsUpdatePayload { + """ + The updated cart. + """ + cart: Cart + + """ + The list of errors that occurred from executing the mutation. + """ + userErrors: [CartUserError!]! +} + """ Represents an error that happens during execution of a cart mutation. """ @@ -1551,14 +1646,14 @@ type Checkout implements Node { orderStatusUrl: URL """ - The amount left to be paid. This is equal to the cost of the line items, taxes and shipping minus discounts and gift cards. + The amount left to be paid. This is equal to the cost of the line items, taxes, and shipping, minus discounts and gift cards. """ - paymentDue: Money! @deprecated(reason: "Use `paymentDueV2` instead.") + paymentDue: MoneyV2! """ The amount left to be paid. This is equal to the cost of the line items, duties, taxes, and shipping, minus discounts and gift cards. """ - paymentDueV2: MoneyV2! + paymentDueV2: MoneyV2! @deprecated(reason: "Use `paymentDue` instead.") "Whether or not the Checkout is ready and can be completed. Checkouts may\nhave asynchronous operations that can take time to finish. If you want\nto complete a checkout or ensure all the fields are populated and up to\ndate, polling is required until the value is true.\n" ready: Boolean! @@ -1582,14 +1677,14 @@ type Checkout implements Node { shippingLine: ShippingRate """ - Price of the checkout before shipping and taxes. + The price at checkout before shipping and taxes. """ - subtotalPrice: Money! @deprecated(reason: "Use `subtotalPriceV2` instead.") + subtotalPrice: MoneyV2! """ The price at checkout before duties, shipping, and taxes. """ - subtotalPriceV2: MoneyV2! + subtotalPriceV2: MoneyV2! @deprecated(reason: "Use `subtotalPrice` instead.") """ Whether the checkout is tax exempt. @@ -1607,24 +1702,24 @@ type Checkout implements Node { totalDuties: MoneyV2 """ - The sum of all the prices of all the items in the checkout, taxes and discounts included. + The sum of all the prices of all the items in the checkout, including taxes and duties. """ - totalPrice: Money! @deprecated(reason: "Use `totalPriceV2` instead.") + totalPrice: MoneyV2! """ - The sum of all the prices of all the items in the checkout, including duties, taxes, and discounts. + The sum of all the prices of all the items in the checkout, including taxes and duties. """ - totalPriceV2: MoneyV2! + totalPriceV2: MoneyV2! @deprecated(reason: "Use `totalPrice` instead.") """ The sum of all the taxes applied to the line items and shipping lines in the checkout. """ - totalTax: Money! @deprecated(reason: "Use `totalTaxV2` instead.") + totalTax: MoneyV2! """ The sum of all the taxes applied to the line items and shipping lines in the checkout. """ - totalTaxV2: MoneyV2! + totalTaxV2: MoneyV2! @deprecated(reason: "Use `totalTax` instead.") """ The date and time when the checkout was last updated. @@ -1975,6 +2070,11 @@ enum CheckoutErrorCode { """ DISCOUNT_ALREADY_APPLIED + """ + Discount code isn't working right now. Please contact us for help. + """ + DISCOUNT_CODE_APPLICATION_FAILED + """ Discount disabled. """ @@ -2634,6 +2734,9 @@ enum CollectionSortKeys { UPDATED_AT } +"A string containing a hexadecimal representation of a color.\n\nFor example, \"#6A8D48\".\n" +scalar Color + """ A comment on an article. """ @@ -5010,6 +5113,11 @@ type Customer implements HasMetafields { identifiers: [HasMetafieldsIdentifier!]! ): [Metafield]! + """ + The number of orders that the customer has made at the store in their lifetime. + """ + numberOfOrders: UnsignedInt64! + """ The orders associated with the customer. """ @@ -5608,6 +5716,19 @@ scalar DateTime "A signed decimal number, which supports arbitrary precision and is serialized as a string.\n\nExample values: `\"29.99\"`, `\"29.999\"`.\n" scalar Decimal +""" +A delivery address of the buyer that is interacting with the cart. +""" +union DeliveryAddress = MailingAddress + +"The input fields for delivery address preferences.\n" +input DeliveryAddressInput { + """ + A delivery address preference of a buyer that is interacting with the cart. + """ + deliveryAddress: MailingAddressInput +} + """ List of different delivery method types. """ @@ -5924,7 +6045,7 @@ type Filter { values: [FilterValue!]! } -"The type of data that the filter group represents.\n\nFor more information, refer to [Filter products in a collection with the Storefront API]\n(https://shopify.dev/api/examples/filter-products).\n" +"The type of data that the filter group represents.\n\nFor more information, refer to [Filter products in a collection with the Storefront API]\n(https://shopify.dev/custom-storefronts/products-collections/filter-products).\n" enum FilterType { """ A boolean value. @@ -6124,7 +6245,7 @@ input GeoCoordinateInput { longitude: Float! } -"A string containing HTML code. Refer to the [HTML spec](https://html.spec.whatwg.org/#elements-3) for a\ncomplete list of HTML elements.\n\nExample value: `\"

Grey cotton knit sweater.

\"`.\n" +"A string containing HTML code. Refer to the [HTML spec](https://html.spec.whatwg.org/#elements-3) for a\ncomplete list of HTML elements.\n\nExample value: `\"

Grey cotton knit sweater.

\"`\n" scalar HTML """ @@ -7673,6 +7794,31 @@ type Metafield implements Node { """ reference: MetafieldReference + """ + A list of reference objects if the metafield's type is a resource reference list. + """ + references( + """ + Returns the elements that come after the specified cursor. + """ + after: String + + """ + Returns the elements that come before the specified cursor. + """ + before: String + + """ + Returns up to the first `n` elements from the list. + """ + first: Int + + """ + Returns up to the last `n` elements from the list. + """ + last: Int + ): MetafieldReferenceConnection + "The type name of the metafield.\nSee the list of [supported types](https://shopify.dev/apps/metafields/definitions/types).\n" type: String! @@ -7721,13 +7867,178 @@ union MetafieldParentResource = "Returns the resource which is being referred to by a metafield.\n" union MetafieldReference = - GenericFile + Collection + | GenericFile | MediaImage + | Metaobject | Page | Product | ProductVariant | Video +"An auto-generated type for paginating through multiple MetafieldReferences.\n" +type MetafieldReferenceConnection { + """ + A list of edges. + """ + edges: [MetafieldReferenceEdge!]! + + """ + A list of the nodes contained in MetafieldReferenceEdge. + """ + nodes: [MetafieldReference!]! + + """ + Information to aid in pagination. + """ + pageInfo: PageInfo! +} + +"An auto-generated type which holds one MetafieldReference and a cursor during pagination.\n" +type MetafieldReferenceEdge { + """ + A cursor for use in pagination. + """ + cursor: String! + + """ + The item at the end of MetafieldReferenceEdge. + """ + node: MetafieldReference! +} + +""" +An instance of a user-defined model based on a MetaobjectDefinition. +""" +type Metaobject implements Node { + """ + Accesses a field of the object by key. + """ + field( + """ + The key of the field. + """ + key: String! + ): MetaobjectField + + "All object fields with defined values.\nOmitted object keys can be assumed null, and no guarantees are made about field order.\n" + fields: [MetaobjectField!]! + + """ + The unique handle of the metaobject. Useful as a custom ID. + """ + handle: String! + + """ + A globally-unique identifier. + """ + id: ID! + + """ + The type of the metaobject. Defines the namespace of its associated metafields. + """ + type: String! + + """ + The date and time when the metaobject was last updated. + """ + updatedAt: DateTime! +} + +"An auto-generated type for paginating through multiple Metaobjects.\n" +type MetaobjectConnection { + """ + A list of edges. + """ + edges: [MetaobjectEdge!]! + + """ + A list of the nodes contained in MetaobjectEdge. + """ + nodes: [Metaobject!]! + + """ + Information to aid in pagination. + """ + pageInfo: PageInfo! +} + +"An auto-generated type which holds one Metaobject and a cursor during pagination.\n" +type MetaobjectEdge { + """ + A cursor for use in pagination. + """ + cursor: String! + + """ + The item at the end of MetaobjectEdge. + """ + node: Metaobject! +} + +""" +Provides the value of a Metaobject field. +""" +type MetaobjectField { + """ + The field key. + """ + key: String! + + """ + A referenced object if the field type is a resource reference. + """ + reference: MetafieldReference + + """ + A list of referenced objects if the field type is a resource reference list. + """ + references( + """ + Returns the elements that come after the specified cursor. + """ + after: String + + """ + Returns the elements that come before the specified cursor. + """ + before: String + + """ + Returns up to the first `n` elements from the list. + """ + first: Int + + """ + Returns up to the last `n` elements from the list. + """ + last: Int + ): MetafieldReferenceConnection + + "The type name of the field.\nSee the list of [supported types](https://shopify.dev/apps/metafields/definitions/types).\n" + type: String! + + """ + The field value. + """ + value: String +} + +""" +The input fields used to retrieve a metaobject by handle. +""" +input MetaobjectHandleInput { + """ + The handle of the metaobject. + """ + handle: String! + + """ + The type of the metaobject. + """ + type: String! +} + """ Represents a Shopify hosted 3D model. """ @@ -7783,11 +8094,6 @@ type Model3dSource { url: String! } -""" -A monetary value string without a currency symbol or code. Example value: `"100.57"`. -""" -scalar Money - """ Specifies the fields for a monetary value with currency. """ @@ -7835,11 +8141,9 @@ type Mutation { cartId: ID! ): CartAttributesUpdatePayload - "Updates customer information associated with a cart.\nBuyer identity is used to determine\n[international pricing](https://shopify.dev/api/examples/international-pricing#create-a-checkout)\nand should match the customer's shipping address.\n" + "Updates customer information associated with a cart.\nBuyer identity is used to determine\n[international pricing](https://shopify.dev/custom-storefronts/internationalization/international-pricing)\nand should match the customer's shipping address.\n" cartBuyerIdentityUpdate( - """ - The customer associated with the cart. Used to determine [international pricing](https://shopify.dev/api/examples/international-pricing#create-a-checkout). Buyer identity should match the customer's shipping address. - """ + "The customer associated with the cart. Used to determine\n[international pricing](https://shopify.dev/custom-storefronts/internationalization/international-pricing).\nBuyer identity should match the customer's shipping address.\n" buyerIdentity: CartBuyerIdentityInput! """ @@ -7931,6 +8235,21 @@ type Mutation { note: String ): CartNoteUpdatePayload + """ + Update the selected delivery options for a delivery group. + """ + cartSelectedDeliveryOptionsUpdate( + """ + The ID of the cart. + """ + cartId: ID! + + """ + The selected delivery options. + """ + selectedDeliveryOptions: [CartSelectedDeliveryOptionInput!]! + ): CartSelectedDeliveryOptionsUpdatePayload + """ Updates the attributes of a checkout if `allowPartialAddresses` is `true`. """ @@ -8325,7 +8644,7 @@ type Mutation { customerAccessToken: String! ): CustomerDefaultAddressUpdatePayload - "\"Sends a reset password email to the customer. The reset password email contains a reset password URL and token that you can pass to the [`customerResetByUrl`](https://shopify.dev/api/storefront/latest/mutations/customerResetByUrl) or [`customerReset`](https://shopify.dev/api/storefront/latest/mutations/customerReset) mutation to reset the customer password.\"\n" + "Sends a reset password email to the customer. The reset password\nemail contains a reset password URL and token that you can pass to\nthe [`customerResetByUrl`](https://shopify.dev/api/storefront/latest/mutations/customerResetByUrl) or\n[`customerReset`](https://shopify.dev/api/storefront/latest/mutations/customerReset) mutation to reset the\ncustomer password.\n\nThis mutation is throttled by IP. With authenticated access,\nyou can provide a [`Shopify-Storefront-Buyer-IP`](https://shopify.dev/api/usage/authentication#optional-ip-header) instead of the request IP.\n\nMake sure that the value provided to `Shopify-Storefront-Buyer-IP` is trusted. Unthrottled access to this\nmutation presents a security risk.\n" customerRecover( """ The email address of the customer to recover. @@ -8432,6 +8751,11 @@ type Order implements HasMetafields & Node { """ currentTotalTax: MoneyV2! + """ + A list of the custom attributes added to the order. + """ + customAttributes: [Attribute!]! + """ The locale code in which this specific order happened. """ @@ -8592,12 +8916,12 @@ type Order implements HasMetafields & Node { """ Price of the order before shipping and taxes. """ - subtotalPrice: Money @deprecated(reason: "Use `subtotalPriceV2` instead.") + subtotalPrice: MoneyV2 """ Price of the order before duties, shipping and taxes. """ - subtotalPriceV2: MoneyV2 + subtotalPriceV2: MoneyV2 @deprecated(reason: "Use `subtotalPrice` instead.") """ List of the order’s successful fulfillments. @@ -8610,45 +8934,45 @@ type Order implements HasMetafields & Node { ): [Fulfillment!] """ - The sum of all the prices of all the items in the order, taxes and discounts included (must be positive). + The sum of all the prices of all the items in the order, duties, taxes and discounts included (must be positive). """ - totalPrice: Money! @deprecated(reason: "Use `totalPriceV2` instead.") + totalPrice: MoneyV2! """ The sum of all the prices of all the items in the order, duties, taxes and discounts included (must be positive). """ - totalPriceV2: MoneyV2! + totalPriceV2: MoneyV2! @deprecated(reason: "Use `totalPrice` instead.") """ The total amount that has been refunded. """ - totalRefunded: Money! @deprecated(reason: "Use `totalRefundedV2` instead.") + totalRefunded: MoneyV2! """ The total amount that has been refunded. """ - totalRefundedV2: MoneyV2! + totalRefundedV2: MoneyV2! @deprecated(reason: "Use `totalRefunded` instead.") """ The total cost of shipping. """ - totalShippingPrice: Money! - @deprecated(reason: "Use `totalShippingPriceV2` instead.") + totalShippingPrice: MoneyV2! """ The total cost of shipping. """ totalShippingPriceV2: MoneyV2! + @deprecated(reason: "Use `totalShippingPrice` instead.") """ The total cost of taxes. """ - totalTax: Money @deprecated(reason: "Use `totalTaxV2` instead.") + totalTax: MoneyV2 """ The total cost of taxes. """ - totalTaxV2: MoneyV2 + totalTaxV2: MoneyV2 @deprecated(reason: "Use `totalTax` instead.") } """ @@ -8697,6 +9021,11 @@ type OrderConnection { Information to aid in pagination. """ pageInfo: PageInfo! + + """ + The total count of Orders. + """ + totalCount: UnsignedInt64! } "An auto-generated type which holds one Order and a cursor during pagination.\n" @@ -9058,12 +9387,12 @@ type Payment implements Node { """ The amount of the payment. """ - amount: Money! @deprecated(reason: "Use `amountV2` instead.") + amount: MoneyV2! """ The amount of the payment. """ - amountV2: MoneyV2! + amountV2: MoneyV2! @deprecated(reason: "Use `amount` instead.") """ The billing address for the payment. @@ -9325,6 +9654,11 @@ type Product implements HasMetafields & Node & OnlineStorePublishable { sortKey: ProductImageSortKeys = POSITION ): ImageConnection! + """ + Whether the product is a gift card. + """ + isGiftCard: Boolean! + """ The media associated with the product. """ @@ -9626,6 +9960,11 @@ input ProductFilter { """ productVendor: String + """ + A product tag to filter on. + """ + tag: String + """ A variant metafield to filter on. """ @@ -9776,12 +10115,12 @@ type ProductVariant implements HasMetafields & Node { """ The compare at price of the variant. This can be used to mark a variant as on sale, when `compareAtPrice` is higher than `price`. """ - compareAtPrice: Money @deprecated(reason: "Use `compareAtPriceV2` instead.") + compareAtPrice: MoneyV2 """ The compare at price of the variant. This can be used to mark a variant as on sale, when `compareAtPriceV2` is higher than `priceV2`. """ - compareAtPriceV2: MoneyV2 + compareAtPriceV2: MoneyV2 @deprecated(reason: "Use `compareAtPrice` instead.") """ Whether a product is out of stock but still available for purchase (used for backorders). @@ -9822,12 +10161,12 @@ type ProductVariant implements HasMetafields & Node { """ The product variant’s price. """ - price: Money! @deprecated(reason: "Use `priceV2` instead.") + price: MoneyV2! """ The product variant’s price. """ - priceV2: MoneyV2! + priceV2: MoneyV2! @deprecated(reason: "Use `price` instead.") """ The product object that the product variant belongs to. @@ -9908,6 +10247,11 @@ type ProductVariant implements HasMetafields & Node { """ last: Int + """ + Used to sort results based on proximity to the provided location. + """ + near: GeoCoordinateInput + """ Reverse the order of the underlying list. """ @@ -10104,9 +10448,7 @@ type QueryRoot { sortKey: BlogSortKeys = ID ): BlogConnection! - """ - Retrieve a cart by its ID. For more information, refer to [Manage a cart with the Storefront API](https://shopify.dev/api/examples/cart). - """ + "Retrieve a cart by its ID. For more information, refer to\n[Manage a cart with the Storefront API](https://shopify.dev/custom-storefronts/cart/manage).\n" cart( """ The ID of the cart. @@ -10240,6 +10582,61 @@ type QueryRoot { handle: String! ): Menu + """ + Fetch a specific Metaobject by one of its unique identifiers. + """ + metaobject( + """ + The handle and type of the metaobject. + """ + handle: MetaobjectHandleInput + + """ + The ID of the metaobject. + """ + id: ID + ): Metaobject + + """ + All active metaobjects for the shop. + """ + metaobjects( + """ + Returns the elements that come after the specified cursor. + """ + after: String + + """ + Returns the elements that come before the specified cursor. + """ + before: String + + """ + Returns up to the first `n` elements from the list. + """ + first: Int + + """ + Returns up to the last `n` elements from the list. + """ + last: Int + + """ + Reverse the order of the underlying list. + """ + reverse: Boolean = false + + """ + The key of a field to sort with. Supports "id" and "updated_at". + """ + sortKey: String + + """ + The type of metaobject to retrieve. + """ + type: String! + ): MetaobjectConnection! + """ Returns a specific node by ID. """ @@ -10446,6 +10843,9 @@ type QueryRoot { """ last: Int + "Supported filter parameters:\n - `created_at`\n - `path`\n - `target`\n\nSee the detailed [search syntax](https://shopify.dev/api/usage/search-syntax)\nfor more information about using filters.\n" + query: String + """ Reverse the order of the underlying list. """ @@ -10901,12 +11301,12 @@ type ShippingRate { """ Price of this shipping rate. """ - price: Money! @deprecated(reason: "Use `priceV2` instead.") + price: MoneyV2! """ Price of this shipping rate. """ - priceV2: MoneyV2! + priceV2: MoneyV2! @deprecated(reason: "Use `price` instead.") """ Title of this shipping rate. @@ -10918,6 +11318,11 @@ type ShippingRate { Shop represents a collection of the general settings and information about the shop. """ type Shop implements HasMetafields & Node { + """ + The shop's branding configuration. + """ + brand: Brand + """ A description of the shop. """ @@ -11180,12 +11585,12 @@ type Transaction { """ The amount of money that the transaction was for. """ - amount: Money! @deprecated(reason: "Use `amountV2` instead.") + amount: MoneyV2! """ The amount of money that the transaction was for. """ - amountV2: MoneyV2! + amountV2: MoneyV2! @deprecated(reason: "Use `amount` instead.") """ The kind of the transaction. @@ -11392,6 +11797,9 @@ enum UnitSystem { METRIC_SYSTEM } +"An unsigned 64-bit integer. Represents whole numeric values between 0 and 2^64 - 1 encoded as a string of base-10 digits.\n\nExample value: `\"50\"`.\n" +scalar UnsignedInt64 + """ A redirect on the online store. """ diff --git a/packages/shopify/src/api/endpoints/checkout/get-checkout.ts b/packages/shopify/src/api/endpoints/checkout/get-checkout.ts index bed5c7b3c..164c84dbc 100644 --- a/packages/shopify/src/api/endpoints/checkout/get-checkout.ts +++ b/packages/shopify/src/api/endpoints/checkout/get-checkout.ts @@ -1,34 +1,15 @@ -import { - SHOPIFY_CHECKOUT_ID_COOKIE, - SHOPIFY_CHECKOUT_URL_COOKIE, - SHOPIFY_CUSTOMER_TOKEN_COOKIE, -} from '../../../const' -import associateCustomerWithCheckoutMutation from '../../../utils/mutations/associate-customer-with-checkout' +import { SHOPIFY_CART_URL_COOKIE } from '../../../const' import type { CheckoutEndpoint } from '.' const getCheckout: CheckoutEndpoint['handlers']['getCheckout'] = async ({ req, - config, }) => { const { cookies } = req - const checkoutUrl = cookies.get(SHOPIFY_CHECKOUT_URL_COOKIE)?.value - const customerCookie = cookies.get(SHOPIFY_CUSTOMER_TOKEN_COOKIE)?.value + const cartUrl = cookies.get(SHOPIFY_CART_URL_COOKIE)?.value - if (customerCookie) { - try { - await config.fetch(associateCustomerWithCheckoutMutation, { - variables: { - checkoutId: cookies.get(SHOPIFY_CHECKOUT_ID_COOKIE)?.value, - customerAccessToken: cookies.get(SHOPIFY_CUSTOMER_TOKEN_COOKIE) - ?.value, - }, - }) - } catch (error) { - console.error(error) - } + return { + redirectTo: cartUrl || '/cart', } - - return { redirectTo: checkoutUrl ?? '/cart' } } export default getCheckout diff --git a/packages/shopify/src/api/index.ts b/packages/shopify/src/api/index.ts index 6412adaca..f9b36b654 100644 --- a/packages/shopify/src/api/index.ts +++ b/packages/shopify/src/api/index.ts @@ -8,7 +8,7 @@ import { API_URL, API_TOKEN, SHOPIFY_CUSTOMER_TOKEN_COOKIE, - SHOPIFY_CHECKOUT_ID_COOKIE, + SHOPIFY_CART_ID_COOKIE, } from '../const' import fetchGraphqlApi from './utils/fetch-graphql-api' @@ -40,7 +40,7 @@ const config: ShopifyConfig = { commerceUrl: API_URL, apiToken: API_TOKEN, customerCookie: SHOPIFY_CUSTOMER_TOKEN_COOKIE, - cartCookie: SHOPIFY_CHECKOUT_ID_COOKIE, + cartCookie: SHOPIFY_CART_ID_COOKIE, cartCookieMaxAge: ONE_DAY * 30, fetch: fetchGraphqlApi, } diff --git a/packages/shopify/src/cart/use-add-item.tsx b/packages/shopify/src/cart/use-add-item.tsx index b485acfa5..ab71ef616 100644 --- a/packages/shopify/src/cart/use-add-item.tsx +++ b/packages/shopify/src/cart/use-add-item.tsx @@ -1,23 +1,28 @@ -import { useCallback } from 'react' +import type { AddItemHook } from '@vercel/commerce/types/cart' import type { MutationHook } from '@vercel/commerce/utils/types' + +import type { + CartLinesAddMutation, + CartLinesAddMutationVariables, +} from '../../schema' + +import { useCallback } from 'react' import { CommerceError } from '@vercel/commerce/utils/errors' import useAddItem, { UseAddItem } from '@vercel/commerce/cart/use-add-item' -import type { AddItemHook } from '@vercel/commerce/types/cart' + import useCart from './use-cart' -import { - checkoutLineItemAddMutation, - getCheckoutId, - checkoutToCart, - checkoutCreate, -} from '../utils' -import { Mutation, MutationCheckoutLineItemsAddArgs } from '../../schema' +import { normalizeCart } from '../utils/normalize' +import { getCartId, cartCreate } from '../utils/cart' +import throwUserErrors from '../utils/throw-user-errors' + +import { cartLinesAddMutation } from '../utils/mutations/cart-mutations' export default useAddItem as UseAddItem export const handler: MutationHook = { fetchOptions: { - query: checkoutLineItemAddMutation, + query: cartLinesAddMutation, }, async fetcher({ input: item, options, fetch }) { if ( @@ -29,29 +34,33 @@ export const handler: MutationHook = { }) } - const lineItems = [ + const lines = [ { - variantId: item.variantId, + merchandiseId: item.variantId, quantity: item.quantity ?? 1, }, ] - let checkoutId = getCheckoutId() + let cartId = getCartId() - if (!checkoutId) { - return checkoutToCart(await checkoutCreate(fetch, lineItems)) + if (!cartId) { + const cart = await cartCreate(fetch, lines) + return normalizeCart(cart) } else { - const { checkoutLineItemsAdd } = await fetch< - Mutation, - MutationCheckoutLineItemsAddArgs + const { cartLinesAdd } = await fetch< + CartLinesAddMutation, + CartLinesAddMutationVariables >({ ...options, variables: { - checkoutId, - lineItems, + cartId, + lines, }, }) - return checkoutToCart(checkoutLineItemsAdd) + + throwUserErrors(cartLinesAdd?.userErrors) + + return normalizeCart(cartLinesAdd?.cart) } }, useHook: diff --git a/packages/shopify/src/cart/use-cart.tsx b/packages/shopify/src/cart/use-cart.tsx index 2400debb1..92ca02b0b 100644 --- a/packages/shopify/src/cart/use-cart.tsx +++ b/packages/shopify/src/cart/use-cart.tsx @@ -1,40 +1,33 @@ import type { SWRHook } from '@vercel/commerce/utils/types' import type { GetCartHook } from '@vercel/commerce/types/cart' +import type { GetCartQueryVariables, QueryRoot } from '../../schema' import { useMemo } from 'react' -import useCommerceCart, { type UseCart } from '@vercel/commerce/cart/use-cart' - -import { checkoutToCart } from '../utils' -import getCheckoutQuery from '../utils/queries/get-checkout-query' import Cookies from 'js-cookie' +import useCommerceCart, { UseCart } from '@vercel/commerce/cart/use-cart' -import { - SHOPIFY_CHECKOUT_ID_COOKIE, - SHOPIFY_CHECKOUT_URL_COOKIE, -} from '../const' +import { SHOPIFY_CART_ID_COOKIE } from '../const' + +import { setCartUrlCookie } from '../utils/cart' +import { normalizeCart } from '../utils/normalize' +import { getCartQuery } from '../utils/queries/get-cart-query' export default useCommerceCart as UseCart - export const handler: SWRHook = { fetchOptions: { - query: getCheckoutQuery, + query: getCartQuery, }, async fetcher({ input: { cartId }, options, fetch }) { if (cartId) { - const { node: checkout } = await fetch({ + let { cart } = await fetch({ ...options, - variables: { - checkoutId: cartId, - }, + variables: { cartId }, }) - if (checkout?.completedAt) { - Cookies.remove(SHOPIFY_CHECKOUT_ID_COOKIE) - Cookies.remove(SHOPIFY_CHECKOUT_URL_COOKIE) - return null + if (cart) { + setCartUrlCookie(cart.checkoutUrl) + return normalizeCart(cart) } else { - return checkoutToCart({ - checkout, - }) + Cookies.remove(SHOPIFY_CART_ID_COOKIE) } } return null @@ -50,7 +43,7 @@ export const handler: SWRHook = { Object.create(response, { isEmpty: { get() { - return (response.data?.lineItems.length ?? 0) <= 0 + return (response.data?.lineItems?.length ?? 0) <= 0 }, enumerable: true, }, diff --git a/packages/shopify/src/cart/use-remove-item.tsx b/packages/shopify/src/cart/use-remove-item.tsx index eefeed135..922952e3a 100644 --- a/packages/shopify/src/cart/use-remove-item.tsx +++ b/packages/shopify/src/cart/use-remove-item.tsx @@ -1,19 +1,33 @@ -import { useCallback } from 'react' import type { MutationHookContext, HookFetcherContext, } from '@vercel/commerce/utils/types' -import { ValidationError } from '@vercel/commerce/utils/errors' -import useRemoveItem, { - UseRemoveItem, -} from '@vercel/commerce/cart/use-remove-item' + +import type { + CartLinesRemoveMutation, + CartLinesRemoveMutationVariables, +} from '../../schema' + import type { Cart, LineItem, RemoveItemHook, } from '@vercel/commerce/types/cart' + +import { useCallback } from 'react' +import { ValidationError } from '@vercel/commerce/utils/errors' + +import useRemoveItem, { + UseRemoveItem, +} from '@vercel/commerce/cart/use-remove-item' + import useCart from './use-cart' +import { getCartId } from '../utils/cart' +import { normalizeCart } from '../utils/normalize' +import { cartLinesRemoveMutation } from '../utils/mutations/cart-mutations' +import throwUserErrors from '../utils/throw-user-errors' + export type RemoveItemFn = T extends LineItem ? (input?: RemoveItemActionInput) => Promise : (input: RemoveItemActionInput) => Promise @@ -24,28 +38,26 @@ export type RemoveItemActionInput = T extends LineItem export default useRemoveItem as UseRemoveItem -import { - checkoutLineItemRemoveMutation, - getCheckoutId, - checkoutToCart, -} from '../utils' - -import { Mutation, MutationCheckoutLineItemsRemoveArgs } from '../../schema' - export const handler = { fetchOptions: { - query: checkoutLineItemRemoveMutation, + query: cartLinesRemoveMutation, }, async fetcher({ input: { itemId }, options, fetch, }: HookFetcherContext) { - const data = await fetch({ + const data = await fetch< + CartLinesRemoveMutation, + CartLinesRemoveMutationVariables + >({ ...options, - variables: { checkoutId: getCheckoutId(), lineItemIds: [itemId] }, + variables: { cartId: getCartId(), lineIds: [itemId] }, }) - return checkoutToCart(data.checkoutLineItemsRemove) + + throwUserErrors(data.cartLinesRemove?.userErrors) + + return normalizeCart(data.cartLinesRemove?.cart) }, useHook: ({ fetch }: MutationHookContext) => diff --git a/packages/shopify/src/cart/use-update-item.tsx b/packages/shopify/src/cart/use-update-item.tsx index 3767c6174..0c80718be 100644 --- a/packages/shopify/src/cart/use-update-item.tsx +++ b/packages/shopify/src/cart/use-update-item.tsx @@ -1,26 +1,29 @@ -import type { UpdateItemHook, LineItem } from '@vercel/commerce/types/cart' import type { - Mutation, - MutationCheckoutLineItemsUpdateArgs, + CartLinesUpdateMutation, + CartLinesUpdateMutationVariables, } from '../../schema' + import type { HookFetcherContext, MutationHookContext, } from '@vercel/commerce/utils/types' +import type { UpdateItemHook, LineItem } from '@vercel/commerce/types/cart' + import { useCallback } from 'react' import debounce from 'lodash.debounce' import { ValidationError } from '@vercel/commerce/utils/errors' import useUpdateItem, { - type UseUpdateItem, + UseUpdateItem, } from '@vercel/commerce/cart/use-update-item' + import useCart from './use-cart' + import { handler as removeItemHandler } from './use-remove-item' -import { - getCheckoutId, - checkoutLineItemUpdateMutation, - checkoutToCart, -} from '../utils' + +import { getCartId } from '../utils/cart' +import { normalizeCart } from '../utils/normalize' +import { cartLinesUpdateMutation } from '../utils/mutations/cart-mutations' export type UpdateItemActionInput = T extends LineItem ? Partial @@ -30,7 +33,7 @@ export default useUpdateItem as UseUpdateItem export const handler = { fetchOptions: { - query: checkoutLineItemUpdateMutation, + query: cartLinesUpdateMutation, }, async fetcher({ input: { itemId, item }, @@ -51,14 +54,14 @@ export const handler = { message: 'The item quantity has to be a valid integer', }) } - const { checkoutLineItemsUpdate } = await fetch< - Mutation, - MutationCheckoutLineItemsUpdateArgs + const { cartLinesUpdate } = await fetch< + CartLinesUpdateMutation, + CartLinesUpdateMutationVariables >({ ...options, variables: { - checkoutId: getCheckoutId(), - lineItems: [ + cartId: getCartId(), + lines: [ { id: itemId, quantity: item.quantity, @@ -67,7 +70,7 @@ export const handler = { }, }) - return checkoutToCart(checkoutLineItemsUpdate) + return normalizeCart(cartLinesUpdate?.cart) }, useHook: ({ fetch }: MutationHookContext) => diff --git a/packages/shopify/src/const.ts b/packages/shopify/src/const.ts index fb15f9708..e44eefc8f 100644 --- a/packages/shopify/src/const.ts +++ b/packages/shopify/src/const.ts @@ -1,6 +1,6 @@ -export const SHOPIFY_CHECKOUT_ID_COOKIE = 'shopify_checkoutId' +export const SHOPIFY_CART_ID_COOKIE = 'shopify_cartId' -export const SHOPIFY_CHECKOUT_URL_COOKIE = 'shopify_checkoutUrl' +export const SHOPIFY_CART_URL_COOKIE = 'shopify_cartUrl' export const SHOPIFY_CUSTOMER_TOKEN_COOKIE = 'shopify_customerToken' @@ -8,6 +8,6 @@ export const STORE_DOMAIN = process.env.NEXT_PUBLIC_SHOPIFY_STORE_DOMAIN export const SHOPIFY_COOKIE_EXPIRE = 30 -export const API_URL = `https://${STORE_DOMAIN}/api/2022-07/graphql.json` +export const API_URL = `https://${STORE_DOMAIN}/api/2023-01/graphql.json` export const API_TOKEN = process.env.NEXT_PUBLIC_SHOPIFY_STOREFRONT_ACCESS_TOKEN diff --git a/packages/shopify/src/provider.ts b/packages/shopify/src/provider.ts index 00db5c1d3..bfa102ac8 100644 --- a/packages/shopify/src/provider.ts +++ b/packages/shopify/src/provider.ts @@ -1,4 +1,4 @@ -import { SHOPIFY_CHECKOUT_ID_COOKIE } from './const' +import { SHOPIFY_CART_ID_COOKIE } from './const' import { handler as useCart } from './cart/use-cart' import { handler as useAddItem } from './cart/use-add-item' @@ -16,7 +16,7 @@ import fetcher from './fetcher' export const shopifyProvider = { locale: 'en-us', - cartCookie: SHOPIFY_CHECKOUT_ID_COOKIE, + cartCookie: SHOPIFY_CART_ID_COOKIE, fetcher, cart: { useCart, useAddItem, useUpdateItem, useRemoveItem }, customer: { useCustomer }, diff --git a/packages/shopify/src/utils/cart.ts b/packages/shopify/src/utils/cart.ts new file mode 100644 index 000000000..be52f306c --- /dev/null +++ b/packages/shopify/src/utils/cart.ts @@ -0,0 +1,65 @@ +import type { FetcherOptions } from '@vercel/commerce/utils/types' + +import type { + CartLineInput, + CartCreateMutation, + CartDetailsFragment, + CartCreateMutationVariables, +} from '../../schema' + +import Cookies from 'js-cookie' +import { cartCreateMutation } from './mutations/cart-mutations' +import throwUserErrors from './throw-user-errors' + +import { + SHOPIFY_CART_ID_COOKIE, + SHOPIFY_CART_URL_COOKIE, + SHOPIFY_COOKIE_EXPIRE, +} from '../const' + +export const setCartUrlCookie = (cartUrl: string) => { + if (cartUrl) { + const oldCookie = Cookies.get(SHOPIFY_CART_URL_COOKIE) + if (oldCookie !== cartUrl) { + Cookies.set(SHOPIFY_CART_URL_COOKIE, cartUrl, { + expires: SHOPIFY_COOKIE_EXPIRE, + }) + } + } +} + +export const getCartId = (id?: string) => { + return id || Cookies.get(SHOPIFY_CART_ID_COOKIE) +} + +export const cartCreate = async ( + fetch: (options: FetcherOptions) => Promise, + lines?: Array | CartLineInput +): Promise => { + const { cartCreate } = await fetch< + CartCreateMutation, + CartCreateMutationVariables + >({ + query: cartCreateMutation, + variables: { + input: { + lines, + }, + }, + }) + + const cart = cartCreate?.cart + + throwUserErrors(cartCreate?.userErrors) + + if (cart?.id) { + const options = { + expires: SHOPIFY_COOKIE_EXPIRE, + } + Cookies.set(SHOPIFY_CART_ID_COOKIE, cart.id, options) + } + + setCartUrlCookie(cart?.checkoutUrl) + + return cart +} diff --git a/packages/shopify/src/utils/checkout-create.ts b/packages/shopify/src/utils/checkout-create.ts deleted file mode 100644 index 2f681c95d..000000000 --- a/packages/shopify/src/utils/checkout-create.ts +++ /dev/null @@ -1,45 +0,0 @@ -import Cookies from 'js-cookie' - -import { - SHOPIFY_CHECKOUT_ID_COOKIE, - SHOPIFY_CHECKOUT_URL_COOKIE, - SHOPIFY_COOKIE_EXPIRE, -} from '../const' - -import checkoutCreateMutation from './mutations/checkout-create' -import { - CheckoutCreatePayload, - CheckoutLineItemInput, - Mutation, - MutationCheckoutCreateArgs, -} from '../../schema' -import { FetcherOptions } from '@vercel/commerce/utils/types' - -export const checkoutCreate = async ( - fetch: (options: FetcherOptions) => Promise, - lineItems: CheckoutLineItemInput[] -): Promise => { - const { checkoutCreate } = await fetch({ - query: checkoutCreateMutation, - variables: { - input: { lineItems }, - }, - }) - - const checkout = checkoutCreate?.checkout - - if (checkout) { - const checkoutId = checkout?.id - const options = { - expires: SHOPIFY_COOKIE_EXPIRE, - } - Cookies.set(SHOPIFY_CHECKOUT_ID_COOKIE, checkoutId, options) - if (checkout?.webUrl) { - Cookies.set(SHOPIFY_CHECKOUT_URL_COOKIE, checkout.webUrl, options) - } - } - - return checkoutCreate! -} - -export default checkoutCreate diff --git a/packages/shopify/src/utils/checkout-to-cart.ts b/packages/shopify/src/utils/checkout-to-cart.ts deleted file mode 100644 index a487eeee5..000000000 --- a/packages/shopify/src/utils/checkout-to-cart.ts +++ /dev/null @@ -1,41 +0,0 @@ -import type { Cart } from '@vercel/commerce/types/cart' -import { CommerceError } from '@vercel/commerce/utils/errors' - -import { - CheckoutLineItemsAddPayload, - CheckoutLineItemsRemovePayload, - CheckoutLineItemsUpdatePayload, - CheckoutCreatePayload, - CheckoutUserError, - Checkout, - Maybe, -} from '../../schema' - -import { normalizeCart } from './normalize' -import throwUserErrors from './throw-user-errors' - -export type CheckoutQuery = { - checkout: Checkout - checkoutUserErrors?: Array -} - -export type CheckoutPayload = - | CheckoutLineItemsAddPayload - | CheckoutLineItemsUpdatePayload - | CheckoutLineItemsRemovePayload - | CheckoutCreatePayload - | CheckoutQuery - -const checkoutToCart = (checkoutPayload?: Maybe): Cart => { - throwUserErrors(checkoutPayload?.checkoutUserErrors) - - if (!checkoutPayload?.checkout) { - throw new CommerceError({ - message: 'Missing checkout object from response', - }) - } - - return normalizeCart(checkoutPayload?.checkout) -} - -export default checkoutToCart diff --git a/packages/shopify/src/utils/fragments/cart-details-fragment.ts b/packages/shopify/src/utils/fragments/cart-details-fragment.ts new file mode 100644 index 000000000..4b50d7dad --- /dev/null +++ b/packages/shopify/src/utils/fragments/cart-details-fragment.ts @@ -0,0 +1,82 @@ +export const cartDetailsFragment = /* GraphQL */ ` + fragment CartDetails on Cart { + id + checkoutUrl + createdAt + updatedAt + lines(first: 10) { + edges { + node { + id + quantity + merchandise { + ... on ProductVariant { + id + id + sku + title + selectedOptions { + name + value + } + image { + url + altText + width + height + } + price { + amount + currencyCode + } + compareAtPrice { + amount + currencyCode + } + product { + title + handle + } + } + } + } + } + } + attributes { + key + value + } + buyerIdentity { + email + customer { + id + } + } + estimatedCost { + totalAmount { + amount + currencyCode + } + subtotalAmount { + amount + currencyCode + } + totalTaxAmount { + amount + currencyCode + } + totalDutyAmount { + amount + currencyCode + } + } + } +` + +export const userErrorsFragment = /* GraphQL */ ` + fragment UserErrors on CartUserError { + code + field + message + } +` diff --git a/packages/shopify/src/utils/get-checkout-id.ts b/packages/shopify/src/utils/get-checkout-id.ts deleted file mode 100644 index 11e3802d9..000000000 --- a/packages/shopify/src/utils/get-checkout-id.ts +++ /dev/null @@ -1,8 +0,0 @@ -import Cookies from 'js-cookie' -import { SHOPIFY_CHECKOUT_ID_COOKIE } from '../const' - -const getCheckoutId = (id?: string) => { - return id ?? Cookies.get(SHOPIFY_CHECKOUT_ID_COOKIE) -} - -export default getCheckoutId diff --git a/packages/shopify/src/utils/index.ts b/packages/shopify/src/utils/index.ts index a8454ffca..3c2649c32 100644 --- a/packages/shopify/src/utils/index.ts +++ b/packages/shopify/src/utils/index.ts @@ -3,9 +3,6 @@ export { default as getSearchVariables } from './get-search-variables' export { default as getSortVariables } from './get-sort-variables' export { default as getBrands } from './get-brands' export { default as getCategories } from './get-categories' -export { default as getCheckoutId } from './get-checkout-id' -export { default as checkoutCreate } from './checkout-create' -export { default as checkoutToCart } from './checkout-to-cart' export { default as handleLogin, handleAutomaticLogin } from './handle-login' export { default as handleAccountActivation } from './handle-account-activation' export { default as throwUserErrors } from './throw-user-errors' diff --git a/packages/shopify/src/utils/mutations/cart-mutations.ts b/packages/shopify/src/utils/mutations/cart-mutations.ts new file mode 100644 index 000000000..f702059c3 --- /dev/null +++ b/packages/shopify/src/utils/mutations/cart-mutations.ts @@ -0,0 +1,64 @@ +import { + cartDetailsFragment, + userErrorsFragment, +} from '../fragments/cart-details-fragment' + +export const cartCreateMutation = /* GraphQL */ ` + mutation cartCreate($input: CartInput = {}) { + cartCreate(input: $input) { + cart { + ...CartDetails + } + userErrors { + ...UserErrors + } + } + } + ${cartDetailsFragment} + ${userErrorsFragment} +` + +export const cartLinesAddMutation = /* GraphQL */ ` + mutation cartLinesAdd($lines: [CartLineInput!]!, $cartId: ID!) { + cartLinesAdd(lines: $lines, cartId: $cartId) { + cart { + ...CartDetails + } + userErrors { + ...UserErrors + } + } + } + ${cartDetailsFragment} + ${userErrorsFragment} +` + +export const cartLinesRemoveMutation = /* GraphQL */ ` + mutation cartLinesRemove($cartId: ID!, $lineIds: [ID!]!) { + cartLinesRemove(cartId: $cartId, lineIds: $lineIds) { + cart { + ...CartDetails + } + userErrors { + ...UserErrors + } + } + } + ${cartDetailsFragment} + ${userErrorsFragment} +` + +export const cartLinesUpdateMutation = /* GraphQL */ ` + mutation cartLinesUpdate($cartId: ID!, $lines: [CartLineUpdateInput!]!) { + cartLinesUpdate(cartId: $cartId, lines: $lines) { + cart { + ...CartDetails + } + userErrors { + ...UserErrors + } + } + } + ${cartDetailsFragment} + ${userErrorsFragment} +` diff --git a/packages/shopify/src/utils/mutations/checkout-create.ts b/packages/shopify/src/utils/mutations/checkout-create.ts deleted file mode 100644 index 7bff7e757..000000000 --- a/packages/shopify/src/utils/mutations/checkout-create.ts +++ /dev/null @@ -1,19 +0,0 @@ -import { checkoutDetailsFragment } from '../queries/get-checkout-query' - -const checkoutCreateMutation = /* GraphQL */ ` - mutation checkoutCreate($input: CheckoutCreateInput = {}) { - checkoutCreate(input: $input) { - checkoutUserErrors { - code - field - message - } - checkout { - ...checkoutDetails - } - } - } - - ${checkoutDetailsFragment} -` -export default checkoutCreateMutation diff --git a/packages/shopify/src/utils/mutations/checkout-line-item-add.ts b/packages/shopify/src/utils/mutations/checkout-line-item-add.ts deleted file mode 100644 index 02f5b7107..000000000 --- a/packages/shopify/src/utils/mutations/checkout-line-item-add.ts +++ /dev/null @@ -1,22 +0,0 @@ -import { checkoutDetailsFragment } from '../queries/get-checkout-query' - -const checkoutLineItemAddMutation = /* GraphQL */ ` - mutation checkoutLineItemAdd( - $checkoutId: ID! - $lineItems: [CheckoutLineItemInput!]! - ) { - checkoutLineItemsAdd(checkoutId: $checkoutId, lineItems: $lineItems) { - checkoutUserErrors { - code - field - message - } - checkout { - ...checkoutDetails - } - } - } - - ${checkoutDetailsFragment} -` -export default checkoutLineItemAddMutation diff --git a/packages/shopify/src/utils/mutations/checkout-line-item-remove.ts b/packages/shopify/src/utils/mutations/checkout-line-item-remove.ts deleted file mode 100644 index 30cb83028..000000000 --- a/packages/shopify/src/utils/mutations/checkout-line-item-remove.ts +++ /dev/null @@ -1,21 +0,0 @@ -import { checkoutDetailsFragment } from '../queries/get-checkout-query' - -const checkoutLineItemRemoveMutation = /* GraphQL */ ` - mutation checkoutLineItemRemove($checkoutId: ID!, $lineItemIds: [ID!]!) { - checkoutLineItemsRemove( - checkoutId: $checkoutId - lineItemIds: $lineItemIds - ) { - checkoutUserErrors { - code - field - message - } - checkout { - ...checkoutDetails - } - } - } - ${checkoutDetailsFragment} -` -export default checkoutLineItemRemoveMutation diff --git a/packages/shopify/src/utils/mutations/checkout-line-item-update.ts b/packages/shopify/src/utils/mutations/checkout-line-item-update.ts deleted file mode 100644 index fca617fb7..000000000 --- a/packages/shopify/src/utils/mutations/checkout-line-item-update.ts +++ /dev/null @@ -1,22 +0,0 @@ -import { checkoutDetailsFragment } from '../queries/get-checkout-query' - -const checkoutLineItemUpdateMutation = /* GraphQL */ ` - mutation checkoutLineItemUpdate( - $checkoutId: ID! - $lineItems: [CheckoutLineItemUpdateInput!]! - ) { - checkoutLineItemsUpdate(checkoutId: $checkoutId, lineItems: $lineItems) { - checkoutUserErrors { - code - field - message - } - checkout { - ...checkoutDetails - } - } - } - - ${checkoutDetailsFragment} -` -export default checkoutLineItemUpdateMutation diff --git a/packages/shopify/src/utils/mutations/index.ts b/packages/shopify/src/utils/mutations/index.ts index 165fb192d..9aaccb772 100644 --- a/packages/shopify/src/utils/mutations/index.ts +++ b/packages/shopify/src/utils/mutations/index.ts @@ -1,8 +1,4 @@ export { default as customerCreateMutation } from './customer-create' -export { default as checkoutCreateMutation } from './checkout-create' -export { default as checkoutLineItemAddMutation } from './checkout-line-item-add' -export { default as checkoutLineItemUpdateMutation } from './checkout-line-item-update' -export { default as checkoutLineItemRemoveMutation } from './checkout-line-item-remove' export { default as customerAccessTokenCreateMutation } from './customer-access-token-create' export { default as customerAccessTokenDeleteMutation } from './customer-access-token-delete' export { default as customerActivateMutation } from './customer-activate' diff --git a/packages/shopify/src/utils/normalize.ts b/packages/shopify/src/utils/normalize.ts index 066daff33..5d74afa2d 100644 --- a/packages/shopify/src/utils/normalize.ts +++ b/packages/shopify/src/utils/normalize.ts @@ -5,8 +5,6 @@ import type { Category } from '@vercel/commerce/types/site' import type { Product as ShopifyProduct, - Checkout, - CheckoutLineItemEdge, SelectedOption, ImageConnection, ProductVariantConnection, @@ -15,9 +13,11 @@ import type { Page as ShopifyPage, PageEdge, Collection, + CartDetailsFragment, } from '../../schema' import { colorMap } from './colors' +import { CommerceError } from '@vercel/commerce/utils/errors' const money = ({ amount, currencyCode }: MoneyV2) => { return { @@ -67,8 +67,8 @@ const normalizeProductVariants = ({ edges }: ProductVariantConnection) => { selectedOptions, sku, title, - priceV2, - compareAtPriceV2, + price, + compareAtPrice, requiresShipping, availableForSale, }, @@ -77,8 +77,8 @@ const normalizeProductVariants = ({ edges }: ProductVariantConnection) => { id, name: title, sku, - price: +priceV2.amount, - listPrice: +compareAtPriceV2?.amount, + price: +price.amount, + listPrice: +compareAtPrice?.amount, requiresShipping, availableForSale, options: selectedOptions.map(({ name, value }: SelectedOption) => { @@ -129,51 +129,57 @@ export function normalizeProduct({ } } -export function normalizeCart(checkout: Checkout): Cart { - return { - id: checkout.id, - url: checkout.webUrl, - customerId: '', - email: '', - createdAt: checkout.createdAt, - currency: { - code: checkout.totalPriceV2?.currencyCode, - }, - taxesIncluded: checkout.taxesIncluded, - lineItems: checkout.lineItems?.edges.map(normalizeLineItem), - lineItemsSubtotalPrice: +checkout.subtotalPriceV2?.amount, - subtotalPrice: +checkout.subtotalPriceV2?.amount, - totalPrice: checkout.totalPriceV2?.amount, - discounts: [], - } -} - function normalizeLineItem({ - node: { id, title, variant, quantity }, -}: CheckoutLineItemEdge): LineItem { + node: { id, merchandise: variant, quantity }, +}: { + node: any +}): LineItem { return { id, - variantId: String(variant?.id), - productId: String(variant?.id), - name: `${title}`, - quantity, + variantId: variant?.id, + productId: variant?.id, + name: variant?.product?.title || variant?.title, + quantity: quantity ?? 0, variant: { - id: String(variant?.id), + id: variant?.id, sku: variant?.sku ?? '', name: variant?.title!, image: { url: variant?.image?.url || '/product-img-placeholder.svg', }, requiresShipping: variant?.requiresShipping ?? false, - price: variant?.priceV2?.amount, - listPrice: variant?.compareAtPriceV2?.amount, + price: +variant?.price?.amount, + listPrice: +variant?.compareAtPrice?.amount, }, - path: String(variant?.product?.handle), + path: variant?.product?.handle, discounts: [], options: variant?.title == 'Default Title' ? [] : variant?.selectedOptions, } } +export function normalizeCart( + cart: CartDetailsFragment | undefined | null +): Cart { + if (!cart) { + throw new CommerceError({ message: 'Missing cart details' }) + } + return { + id: cart.id, + customerId: cart.buyerIdentity?.customer?.id, + email: cart.buyerIdentity?.email ?? '', + createdAt: cart.createdAt, + currency: { + code: cart.estimatedCost?.totalAmount?.currencyCode, + }, + taxesIncluded: !!cart.estimatedCost?.totalTaxAmount?.amount, + lineItems: cart.lines?.edges?.map(normalizeLineItem) ?? [], + lineItemsSubtotalPrice: +cart.estimatedCost?.subtotalAmount?.amount, + subtotalPrice: +cart.estimatedCost?.subtotalAmount?.amount, + totalPrice: +cart.estimatedCost?.totalAmount?.amount, + discounts: [], + } +} + export const normalizePage = ( { title: name, handle, ...page }: ShopifyPage, locale: string = 'en-US' diff --git a/packages/shopify/src/utils/queries/get-all-pages-query.ts b/packages/shopify/src/utils/queries/get-all-pages-query.ts index e3aee1f10..b2ebb2a35 100644 --- a/packages/shopify/src/utils/queries/get-all-pages-query.ts +++ b/packages/shopify/src/utils/queries/get-all-pages-query.ts @@ -1,4 +1,4 @@ -export const getAllPagesQuery = /* GraphQL */ ` +const getAllPagesQuery = /* GraphQL */ ` query getAllPages($first: Int = 250) { pages(first: $first) { edges { diff --git a/packages/shopify/src/utils/queries/get-cart-query.ts b/packages/shopify/src/utils/queries/get-cart-query.ts new file mode 100644 index 000000000..4e61a4cb6 --- /dev/null +++ b/packages/shopify/src/utils/queries/get-cart-query.ts @@ -0,0 +1,10 @@ +import { cartDetailsFragment } from '../fragments/cart-details-fragment' + +export const getCartQuery = /* GraphQL */ ` + query getCart($cartId: ID!) { + cart(id: $cartId) { + ...CartDetails + } + } + ${cartDetailsFragment} +` diff --git a/packages/shopify/src/utils/queries/get-checkout-query.ts b/packages/shopify/src/utils/queries/get-checkout-query.ts deleted file mode 100644 index 31c25bb6a..000000000 --- a/packages/shopify/src/utils/queries/get-checkout-query.ts +++ /dev/null @@ -1,70 +0,0 @@ -export const checkoutDetailsFragment = /* GraphQL */ ` - fragment checkoutDetails on Checkout { - id - webUrl - subtotalPriceV2 { - amount - currencyCode - } - totalTaxV2 { - amount - currencyCode - } - totalPriceV2 { - amount - currencyCode - } - completedAt - createdAt - taxesIncluded - lineItems(first: 250) { - pageInfo { - hasNextPage - hasPreviousPage - } - edges { - node { - id - title - variant { - id - sku - title - selectedOptions { - name - value - } - image { - url - altText - width - height - } - priceV2 { - amount - currencyCode - } - compareAtPriceV2 { - amount - currencyCode - } - product { - handle - } - } - quantity - } - } - } - } -` - -const getCheckoutQuery = /* GraphQL */ ` - query getCheckout($checkoutId: ID!) { - node(id: $checkoutId) { - ...checkoutDetails - } - } - ${checkoutDetailsFragment} -` -export default getCheckoutQuery diff --git a/packages/shopify/src/utils/queries/get-customer-id-query.ts b/packages/shopify/src/utils/queries/get-customer-id-query.ts index 076ceb10b..e90e697bb 100644 --- a/packages/shopify/src/utils/queries/get-customer-id-query.ts +++ b/packages/shopify/src/utils/queries/get-customer-id-query.ts @@ -1,4 +1,4 @@ -export const getCustomerQuery = /* GraphQL */ ` +const getCustomerQuery = /* GraphQL */ ` query getCustomerId($customerAccessToken: String!) { customer(customerAccessToken: $customerAccessToken) { id diff --git a/packages/shopify/src/utils/queries/get-customer-query.ts b/packages/shopify/src/utils/queries/get-customer-query.ts index 87e37e68d..b8f11c378 100644 --- a/packages/shopify/src/utils/queries/get-customer-query.ts +++ b/packages/shopify/src/utils/queries/get-customer-query.ts @@ -1,4 +1,4 @@ -export const getCustomerQuery = /* GraphQL */ ` +const getCustomerQuery = /* GraphQL */ ` query getCustomer($customerAccessToken: String!) { customer(customerAccessToken: $customerAccessToken) { id diff --git a/packages/shopify/src/utils/queries/get-page-query.ts b/packages/shopify/src/utils/queries/get-page-query.ts index 7939f0278..7c0d9a1ea 100644 --- a/packages/shopify/src/utils/queries/get-page-query.ts +++ b/packages/shopify/src/utils/queries/get-page-query.ts @@ -1,4 +1,4 @@ -export const getPageQuery = /* GraphQL */ ` +const getPageQuery = /* GraphQL */ ` query getPage($id: ID!) { node(id: $id) { id diff --git a/packages/shopify/src/utils/queries/get-product-query.ts b/packages/shopify/src/utils/queries/get-product-query.ts index 1c4458432..6bca09122 100644 --- a/packages/shopify/src/utils/queries/get-product-query.ts +++ b/packages/shopify/src/utils/queries/get-product-query.ts @@ -40,11 +40,11 @@ const getProductQuery = /* GraphQL */ ` name value } - priceV2 { + price { amount currencyCode } - compareAtPriceV2 { + compareAtPrice { amount currencyCode } diff --git a/packages/shopify/src/utils/queries/index.ts b/packages/shopify/src/utils/queries/index.ts index 953113491..b0a2de1b6 100644 --- a/packages/shopify/src/utils/queries/index.ts +++ b/packages/shopify/src/utils/queries/index.ts @@ -4,7 +4,6 @@ export { default as getAllProductsQuery } from './get-all-products-query' export { default as getAllProductsPathtsQuery } from './get-all-products-paths-query' export { default as getAllProductVendors } from './get-all-product-vendors-query' export { default as getCollectionProductsQuery } from './get-collection-products-query' -export { default as getCheckoutQuery } from './get-checkout-query' export { default as getAllPagesQuery } from './get-all-pages-query' export { default as getPageQuery } from './get-page-query' export { default as getCustomerQuery } from './get-customer-query' diff --git a/packages/shopify/src/utils/throw-user-errors.ts b/packages/shopify/src/utils/throw-user-errors.ts index 2173b2b40..aacc52618 100644 --- a/packages/shopify/src/utils/throw-user-errors.ts +++ b/packages/shopify/src/utils/throw-user-errors.ts @@ -5,13 +5,18 @@ import { CheckoutUserError, CustomerErrorCode, CustomerUserError, + CartUserError, + CartErrorCode, } from '../../schema' -export type UserErrors = Array +export type UserErrors = Array< + CheckoutUserError | CustomerUserError | CartUserError +> export type UserErrorCode = | CustomerErrorCode | CheckoutErrorCode + | CartErrorCode | null | undefined @@ -24,7 +29,7 @@ const getCustomMessage = (code: UserErrorCode, message: string) => { return message } -export const throwUserErrors = (errors?: UserErrors) => { +const throwUserErrors = (errors?: UserErrors) => { if (errors && errors.length) { throw new ValidationError({ errors: errors.map(({ code, message }) => ({