Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/metal-owls-travel.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@bigcommerce/catalyst-client": minor
---

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.
5 changes: 5 additions & 0 deletions packages/client/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ class Client<FetcherRequestInit extends RequestInit = RequestInit> {
customerAccessToken?: string;
fetchOptions?: FetcherRequestInit;
channelId?: string;
locale?: string;
errorPolicy?: GraphQLErrorPolicy;
validateCustomerAccessToken?: boolean;
}): Promise<BigCommerceResponse<TResult>>;
Expand All @@ -97,6 +98,7 @@ class Client<FetcherRequestInit extends RequestInit = RequestInit> {
customerAccessToken?: string;
fetchOptions?: FetcherRequestInit;
channelId?: string;
locale?: string;
errorPolicy?: GraphQLErrorPolicy;
validateCustomerAccessToken?: boolean;
}): Promise<BigCommerceResponse<TResult>>;
Expand All @@ -107,6 +109,7 @@ class Client<FetcherRequestInit extends RequestInit = RequestInit> {
customerAccessToken,
fetchOptions = {} as FetcherRequestInit,
channelId,
locale,
errorPolicy = 'none',
validateCustomerAccessToken = true,
}: {
Expand All @@ -115,6 +118,7 @@ class Client<FetcherRequestInit extends RequestInit = RequestInit> {
customerAccessToken?: string;
fetchOptions?: FetcherRequestInit;
channelId?: string;
locale?: string;
errorPolicy?: GraphQLErrorPolicy;
validateCustomerAccessToken?: boolean;
}): Promise<BigCommerceResponse<TResult>> {
Expand Down Expand Up @@ -142,6 +146,7 @@ class Client<FetcherRequestInit extends RequestInit = RequestInit> {
'X-Bc-Error-On-Invalid-Customer-Access-Token': 'true',
}),
...(this.trustedProxySecret && { 'X-BC-Trusted-Proxy-Secret': this.trustedProxySecret }),
...(locale && { 'Accept-Language': locale }),
...Object.fromEntries(new Headers(additionalFetchHeaders).entries()),
...Object.fromEntries(new Headers(headers).entries()),
},
Expand Down