CartLinesAddPayload
Payload returned by the cartLinesAdd mutation. This object contains the updated cart after adding lines, along with any user errors that occurred during the operation.
Type Definition
type CartLinesAddPayload {
cart: Cart!
userErrors: [UserError]!
}Fields
| Field | Type | Nullability | Description | Relationship |
|---|---|---|---|---|
cart | Cart | Non-nullable | The updated cart after adding lines | References Cart |
userErrors | [UserError] | Non-nullable | List of errors that occurred during cart lines addition | References [UserError] |
Relationships
- cart: This field returns the updated
Cartobject reflecting the current state after lines have been added. It allows clients to access all cart details such as items, totals, and other cart-specific information. - userErrors: This field returns a list of
UserErrorobjects describing any issues encountered during the addition of lines to the cart. This helps clients handle validation or business logic errors gracefully.
Usage Examples
Basic Query
mutation {
cartLinesAdd(cartId: "eyJhbGciOiJIUzI1NiJ9...", lines: [{ merchandiseId: 12345, quantity: 2 }]) {
cart {
id
totalQuantity
}
userErrors {
field
message
}
}
}Field Selection
mutation {
cartLinesAdd(cartId: "eyJhbGciOiJIUzI1NiJ9...", lines: [{ merchandiseId: 67890, quantity: 1 }]) {
cart {
id
createdAt
updatedAt
totalQuantity
cost {
subtotalAmount {
amount
currencyCode
}
}
}
userErrors {
field
message
}
}
}Nested Queries
mutation {
cartLinesAdd(cartId: "eyJhbGciOiJIUzI1NiJ9...", lines: [{ merchandiseId: 54321, quantity: 3 }]) {
cart {
id
lines(first: 5) {
edges {
node {
id
quantity
merchandise {
id
title
price {
amount
currencyCode
}
}
}
}
}
}
userErrors {
field
message
}
}
}Filtering and Sorting
The CartLinesAddPayload type itself does not support filtering or sorting directly. However, the nested cart.lines connection can be queried with arguments such as first, last, after, and before to paginate through cart lines.
Example paginating cart lines after adding:
mutation {
cartLinesAdd(cartId: "eyJhbGciOiJIUzI1NiJ9...", lines: [{ merchandiseId: 98765, quantity: 2 }]) {
cart {
id
lines(first: 10, after: "cursor123") {
edges {
cursor
node {
id
quantity
}
}
pageInfo {
hasNextPage
hasPreviousPage
}
}
}
userErrors {
field
message
}
}
}Implements
This type does not implement any interfaces.
Connections
- The
cartfield connects to theCartobject type, which contains further connections such aslinesrepresenting individual cart items. - The
userErrorsfield is a list ofUserErrorobjects, providing detailed error information.
Related Types
- Cart: Represents the shopping cart with details such as lines, totals, and metadata.
- UserError: Represents an error related to user input or business logic, containing fields like
fieldandmessage.
Best Practices
- Always check the
userErrorsfield after performing thecartLinesAddmutation to handle any validation or business logic errors gracefully. - Use pagination arguments on nested connections like
cart.linesto efficiently manage large carts. - Select only the fields you need from the
cartobject to optimize query performance. - Handle errors in your client application by inspecting the
fieldandmessageinuserErrors.
Notes
- The
cartLinesAddmutation and its payload currently require no authentication, but this may change in future API versions. - The
cartfield in the payload reflects the cart state immediately after the addition operation, ensuring clients have the latest data. - The
userErrorslist will be empty if the operation completes successfully without issues. - For performance, avoid requesting deeply nested fields unless necessary, especially on large carts.
- Use the JWT cart token format for
cartIdto securely identify carts in mutations.
Last updated on