customerCart
Fetch customer cart.
Signature
declare function customerCart(
context: Context,
customQuery?: CustomQuery,
customHeaders?: CustomHeaders
): Promise<ApolloQueryResult<CustomerCartQuery>>;Parameters
| Name | Required | Type | Description |
|---|---|---|---|
context | Required | Context | |
customQuery | Optional | CustomQuery | |
customHeaders | Optional | CustomHeaders |
Referenced Types
- Context
- CustomQuery
- CustomHeaders
ApolloQueryResultCustomerCartQuery
Examples
Simple usage:
import { sdk } from '~/sdk.config.ts';
// fetch customer cart
const { data } = await sdk.magento.customerCart();
// data contains cart details
const email = data?.customerCart?.email;
Creating a custom GraphQL query for customerCart
module.exports = {
integrations: {
magento: {
customQueries: {
'customer-cart-custom-query': ({ variables, metadata }) => ({
variables,
query: `
query customerCart {
customerCart {
${metadata.fields}
}
}`
}),
},
}
}
};Using a custom GraphQL query to reduce the amount of fields returned by the query, when compared to the default query
import { sdk } from '~/sdk.config.ts';
// reduce the amount of fields returned by the query, when compared to the default query
const customQuery = {
customerCart: 'customer-cart-custom-query',
metadata: {
fields: 'id email items { id sku }
}
};
const result = await sdk.magento.customerCart(customQuery);
// result contains cart details with only the fields specified in the custom query