Skip to content

Commit 9e1ad83

Browse files
committed
feat: add locale override parameter to client.fetch
Allows passing a `locale` that will be used to set the outgoing `"Accept-Language"` header sent to the BigCommerce Storefront GraphQL API
1 parent 24afedc commit 9e1ad83

2 files changed

Lines changed: 10 additions & 0 deletions

File tree

.changeset/metal-owls-travel.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@bigcommerce/catalyst-client": minor
3+
---
4+
5+
Allow passing a `locale` that will be used to set the outgoing `"Accept-Language"` header sent to the BigCommerce Storefront GraphQL API. This additional, optional paramter gives you more explicit control over what language you'd like responses to be translated into, [leveraging BigCommerce's resolved locale feature](https://developer.bigcommerce.com/docs/storefront/graphql/multi-language-support#returned-data). To incorporate these changes into your fork, either update your `@bigcommerce/catalyst-client` dependency to `0.16.0` or use the diff associated with this commit as a reference if using the workspace version of the Catalyst client.

packages/client/src/client.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ class Client<FetcherRequestInit extends RequestInit = RequestInit> {
8686
customerAccessToken?: string;
8787
fetchOptions?: FetcherRequestInit;
8888
channelId?: string;
89+
locale?: string;
8990
errorPolicy?: GraphQLErrorPolicy;
9091
validateCustomerAccessToken?: boolean;
9192
}): Promise<BigCommerceResponse<TResult>>;
@@ -97,6 +98,7 @@ class Client<FetcherRequestInit extends RequestInit = RequestInit> {
9798
customerAccessToken?: string;
9899
fetchOptions?: FetcherRequestInit;
99100
channelId?: string;
101+
locale?: string;
100102
errorPolicy?: GraphQLErrorPolicy;
101103
validateCustomerAccessToken?: boolean;
102104
}): Promise<BigCommerceResponse<TResult>>;
@@ -107,6 +109,7 @@ class Client<FetcherRequestInit extends RequestInit = RequestInit> {
107109
customerAccessToken,
108110
fetchOptions = {} as FetcherRequestInit,
109111
channelId,
112+
locale,
110113
errorPolicy = 'none',
111114
validateCustomerAccessToken = true,
112115
}: {
@@ -115,6 +118,7 @@ class Client<FetcherRequestInit extends RequestInit = RequestInit> {
115118
customerAccessToken?: string;
116119
fetchOptions?: FetcherRequestInit;
117120
channelId?: string;
121+
locale?: string;
118122
errorPolicy?: GraphQLErrorPolicy;
119123
validateCustomerAccessToken?: boolean;
120124
}): Promise<BigCommerceResponse<TResult>> {
@@ -142,6 +146,7 @@ class Client<FetcherRequestInit extends RequestInit = RequestInit> {
142146
'X-Bc-Error-On-Invalid-Customer-Access-Token': 'true',
143147
}),
144148
...(this.trustedProxySecret && { 'X-BC-Trusted-Proxy-Secret': this.trustedProxySecret }),
149+
...(locale && { 'Accept-Language': locale }),
145150
...Object.fromEntries(new Headers(additionalFetchHeaders).entries()),
146151
...Object.fromEntries(new Headers(headers).entries()),
147152
},

0 commit comments

Comments
 (0)