getCustomerAddresses
Get customer addresses. Customer must be logged in before calling this method.
Signature
declare function getCustomerAddresses(
context: Context,
customQuery?: CustomQuery,
customHeaders?: CustomHeaders
): Promise<ApolloQueryResult<CustomerQuery>>;Parameters
| Name | Required | Type | Description |
|---|---|---|---|
context | Required | Context | |
customQuery | Optional | CustomQuery | |
customHeaders | Optional | CustomHeaders |
Referenced Types
- Context
- CustomQuery
- CustomHeaders
ApolloQueryResultCustomerQuery
Examples
Simple usage:
import { sdk } from '~/sdk.config.ts';
// fetch customer addresses if customer is logged in
const { data } = await sdk.magento.getCustomerAddresses();
// data contains the customer addresses
data.customer.addresses; // array of customer addressesCreating a custom GraphQL query
module.exports = {
integrations: {
magento: {
customQueries: {
'get-customer-addresses-custom-query': ({ variables, metadata }) => ({
variables,
query: `
query getCustomerAddresses {
customer {
addresses {
${metadata.fields}
}
}
}
`
}),
},
}
}
};Using a custom GraphQL query to reduce the amount of data returned by the query
import { sdk } from '~/sdk.config.ts';
// reduce the amount of fields returned by the query, when compared to the default query
const customQuery = {
getCustomerAddresses: 'get-customer-addresses-custom-query',
metadata: {
fields: 'city'
}
};
const { data } = await sdk.magento.getCustomerAddresses(customQuery);
// data contains the customer addresses with only the city field