From 1b3003ac9c4fad05e8a5826b408bf523fcda4072 Mon Sep 17 00:00:00 2001 From: Melissa Luu Date: Mon, 23 Mar 2020 14:50:58 -0400 Subject: [PATCH] Update to always set accept-language header for all requests. Defaults to set wildcard value when language is not set in client initialization. --- .gitignore | 3 +++ README.md | 2 +- src/client.js | 6 +++--- test/client-test.js | 3 +++ 4 files changed, 10 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index a1cd9f7c5..0a6a5cda8 100644 --- a/.gitignore +++ b/.gitignore @@ -18,3 +18,6 @@ index.* # Decrypted secrets secrets.json .nvmrc + +# VSCode settings +.vscode \ No newline at end of file diff --git a/README.md b/README.md index 1edaa8c23..21eb986f6 100644 --- a/README.md +++ b/README.md @@ -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' diff --git a/src/client.js b/src/client.js index 55a48bd64..1bd350913 100644 --- a/src/client.js +++ b/src/client.js @@ -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'; diff --git a/test/client-test.js b/test/client-test.js index 7c79f7ae5..945c0f1ee 100644 --- a/test/client-test.js +++ b/test/client-test.js @@ -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 @@ -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, @@ -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