setConfig static method
Sets the config.
IMPORTANT: preferably call this inside the main function or at least before instantiating other Shopify classes.
adminAccessToken is optional, but required for some admin API calls like deleteCustomer.
storefrontApiVersion is optional, but defaults to "2024-07".
cachePolicy is optional, but defaults to CachePolicy.networkOnly.
language is optional, but defaults to "en".
Used to change language. eg: "en", "np", "fr" etc. Only takes effect if the store supports provided language.
countryCode is optional, but defaults to null.
Used to change currency units. eg: "US", "NP", "JP" etc. Only takes effect if the store supports provided currency.
storefrontCache is optional. Inject a custom GraphQLCache (e.g. backed by
HiveStore for disk persistence) for the Storefront API client.
Defaults to a new in-memory GraphQLCache when omitted.
adminCache is optional. Inject a custom GraphQLCache for the Admin
API client. Defaults to a new in-memory GraphQLCache when omitted.
Implementation
static void setConfig({
required String storefrontAccessToken,
required String storeUrl,
String? adminAccessToken,
String storefrontApiVersion = "2024-07",
CachePolicy? cachePolicy,
String? language,
GraphQLCache? storefrontCache,
GraphQLCache? adminCache,
}) {
_storefrontAccessToken = storefrontAccessToken;
_adminAccessToken = adminAccessToken;
_storeUrl = !storeUrl.contains('http') ? 'https://$storeUrl' : storeUrl;
_storefrontApiVersion = storefrontApiVersion;
_fetchPolicy = cachePolicy;
_graphQLClient = GraphQLClient(
link: HttpLink(
'$_storeUrl/api/$_storefrontApiVersion/graphql.json',
defaultHeaders: {
'X-Shopify-Storefront-Access-Token': _storefrontAccessToken!,
'Accept-Language': language ?? 'en',
},
),
cache: storefrontCache ?? GraphQLCache(),
);
_graphQLClientAdmin = _adminAccessToken == null
? null
: GraphQLClient(
link: HttpLink(
'$_storeUrl/admin/api/$_storefrontApiVersion/graphql.json',
defaultHeaders: {
'X-Shopify-Access-Token': _adminAccessToken!,
'Accept-Language': language ?? 'en',
},
),
cache: adminCache ?? GraphQLCache(),
);
}