Skip to content

Commit

Permalink
Update to always set accept-language header for all requests. Default…
Browse files Browse the repository at this point in the history
…s to set wildcard value when language is not set in client initialization.
  • Loading branch information
melissaluu committed Mar 23, 2020
1 parent 42849c2 commit 1b3003a
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 4 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,6 @@ index.*
# Decrypted secrets
secrets.json
.nvmrc

# VSCode settings
.vscode
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ If your store supports multiple languages, Storefront API can return translated
```javascript
import Client from 'shopify-buy';

// Initializing a client
// Initializing a client to return content in the store's primary language
const client = Client.buildClient({
domain: 'your-shop-name.myshopify.com',
storefrontAccessToken: 'your-storefront-access-token'
Expand Down
6 changes: 3 additions & 3 deletions src/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ class Client {
headers['X-SDK-Variant-Source'] = config.source;
}

if (config.language) {
headers['Accept-Language'] = config.language;
}
const languageHeader = config.language ? config.language : '*';

headers['Accept-Language'] = languageHeader;

if (fetchFunction) {
headers['Content-Type'] = 'application/json';
Expand Down
3 changes: 3 additions & 0 deletions test/client-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ suite('client-test', () => {
assert.equal(passedUrl, `https://${config.domain}/api/${config.apiVersion}/graphql`);
assert.deepEqual(passedFetcherOptions, {
headers: {
'Accept-Language': '*',
'X-SDK-Variant': 'javascript',
'X-SDK-Version': version,
'X-Shopify-Storefront-Access-Token': config.storefrontAccessToken
Expand Down Expand Up @@ -61,6 +62,7 @@ suite('client-test', () => {
assert.equal(passedUrl, `https://${withSourceConfig.domain}/api/${withSourceConfig.apiVersion}/graphql`);
assert.deepEqual(passedFetcherOptions, {
headers: {
'Accept-Language': '*',
'X-SDK-Variant': 'javascript',
'X-SDK-Version': version,
'X-Shopify-Storefront-Access-Token': withSourceConfig.storefrontAccessToken,
Expand Down Expand Up @@ -134,6 +136,7 @@ suite('client-test', () => {
assert.deepEqual(passedHeaders, {
'Content-Type': 'application/json',
Accept: 'application/json',
'Accept-Language': '*',
'X-SDK-Variant': 'javascript',
'X-SDK-Version': version,
'X-Shopify-Storefront-Access-Token': config.storefrontAccessToken
Expand Down

0 comments on commit 1b3003a

Please sign in to comment.