cart
Get cart
Signature
declare function cart(
context: Context,
cartId: string,
customQuery?: CustomQuery,
customHeaders?: CustomHeaders
): Promise<ApolloQueryResult<CartQuery>>;Parameters
| Name | Required | Type | Description |
|---|---|---|---|
context | Required | Context | |
cartId | Required | string | |
customQuery | Optional | CustomQuery | |
customHeaders | Optional | CustomHeaders |
Referenced Types
- Context
- CustomQuery
- CustomHeaders
ApolloQueryResultCartQuery
Examples
Simple usage:
import { sdk } from '~/sdk.config.ts';
// fetch cart with default parameters
const cart = await sdk.magento.cart({ cartId: '123' });Creating a custom GraphQL query for getting cart
module.exports = {
integrations: {
magento: {
customQueries: {
'cart-custom-query': ({ variables, metadata }) => ({
variables,
query: `
query cart($cartId: String!) {
cart(cart_id:$cartId) {
${metadata.fields}
}
}`
`
}),
},
}
}
};Using a custom GraphQL query to fetch cart
import { sdk } from '~/sdk.config.ts';
// reduce the amount of fields returned by the query, when compared to the default query
const customQuery = {
cart: 'cart-custom-query',
metadata: {
fields: 'id items { uid }'
}
};
const cart = await sdk.magento.cart({ cartId: '123'}, customQuery);
// Cart will contain only the fields specified in the custom query.