Alokai

currency

Fetch available currencies in a store.

Signature

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

Parameters

NameRequiredTypeDescription
contextRequiredContext
customQueryOptionalCustomQuery
customHeadersOptionalCustomHeaders

Referenced Types

Examples

Simple usage:

import { sdk } from '~/sdk.config.ts';

// fetch available currencies
const result = await sdk.magento.currency();

// result would be something like:
// {
//   "data": {
//     "currency": {
//       "_currency_code": "EUR",
//       "_currency_symbol": "€",
//       "default_display_currency_code": "EUR",
//       "default_display_currency_symbol": "€",
//       "available_currency_codes": [
//         "EUR",
//         "USD"
//       ],
//       "exchange_rates": [
//         {
//           "currency_to": "EUR",
 //          "rate": 1
 //        },
 //        {
 //          "currency_to": "USD",
 //          "rate": 1.2
 //        }
 //      ]
 //    }
 //  }
 // }

Creating a custom GraphQL query

module.exports = {
  integrations: {
    magento: {
      customQueries: {
        'currency-custom-query': ({ variables, metadata }) => ({
           variables,
           query: `
             query currency {
               currency{
                 ${metadata?.fields}
               }
             }
           `
        }),
      },
    }
  }
};

Using a custom GraphQL query to fetch a list of currencies with limited number of fields

import { sdk } from '~/sdk.config.ts';
// reduce the amount of fields returned by the query, when compared to the default query
const customQuery = {
  currency: 'currency-custom-query',
  metadata: {
    fields: '_currency_code'
  }
};

const result = await sdk.magento.currency(customQuery);

// result will contain only the _currency_code field

On this page