availableStores
Fetch available stores
Signature
declare function availableStores(
context: Context,
customQuery?: CustomQuery,
customHeaders?: CustomHeaders
): Promise<ApolloQueryResult<AvailableStoresQuery>>;Parameters
| Name | Required | Type | Description |
|---|---|---|---|
context | Required | Context | |
customQuery | Optional | CustomQuery | |
customHeaders | Optional | CustomHeaders |
Referenced Types
- Context
- CustomQuery
- CustomHeaders
ApolloQueryResultAvailableStoresQuery
Examples
Simple usage:
import { sdk } from '~/sdk.config.ts';
// fetch available stores
const result = await sdk.magento.availableStores();
// result.data.availableStores contains the available storesCreating a custom GraphQL query
module.exports = {
integrations: {
magento: {
customQueries: {
'available-stores-custom-query': ({ variables, metadata }) => ({
variables,
query: `
query availableStores {
availableStores {
${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 = {
availableStores: 'available-stores-custom-query',
metadata: {
fields: 'code store_name'
}
};
const result = await sdk.magento.availableStores(customQuery);
// result.data.availableStores contains the available stores with only the fields specified in the custom query