countries
Fetch list of countries
Signature
declare function countries(
context: Context,
customQuery?: CustomQuery,
customHeaders?: CustomHeaders
): Promise<ApolloQueryResult<CountriesQuery>>;Parameters
| Name | Required | Type | Description |
|---|---|---|---|
context | Required | Context | |
customQuery | Optional | CustomQuery | |
customHeaders | Optional | CustomHeaders |
Referenced Types
- Context
- CustomQuery
- CustomHeaders
ApolloQueryResultCountriesQuery
Examples
Simple usage:
import { sdk } from '~/sdk.config.ts';
// fetch list of countries
const result = await sdk.magento.countries();
// result.data.countries is an array of countriesCreating a custom GraphQL query
module.exports = {
integrations: {
magento: {
customQueries: {
'countries-custom-query': ({ variables, metadata }) => ({
variables,
query: `
query countriesList {
countries {
${metadata?.fields}
}
}
`
}),
},
}
}
};Using a custom GraphQL query to reduce the amount of fields 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 = {
countries: 'countries-custom-query',
metadata: {
fields: 'full_name_english'
}
};
const result = await sdk.magento.countries(customQuery);
// result.data.countries will only contain the full_name_english field