Alokai

countries

Fetch list of countries

Signature

declare function countries(
	context: Context,
	customQuery?: CustomQuery,
	customHeaders?: CustomHeaders
): Promise<ApolloQueryResult<CountriesQuery>>;

Parameters

NameRequiredTypeDescription
contextRequiredContext
customQueryOptionalCustomQuery
customHeadersOptionalCustomHeaders

Referenced Types

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 countries

Creating 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

On this page