Skip to content

Commit 11fe33f

Browse files
Michael Elsdörferpvdz
authored andcommitted
feat(gatsby-source-shopify): Add support for custom domains (#20204)
* Allow shopName to be a url with a custom domain. * Document use of url for shopName. * Fix lint errors, add test.
1 parent 270e54e commit 11fe33f

File tree

3 files changed

+27
-2
lines changed

3 files changed

+27
-2
lines changed

packages/gatsby-source-shopify/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ plugins: [
3737
// The domain name of your Shopify shop. This is required.
3838
// Example: 'gatsby-source-shopify-test-shop' if your Shopify address is
3939
// 'gatsby-source-shopify-test-shop.myshopify.com'.
40+
// If you are running your shop on a custom domain, you need to use that
41+
// as the shop name, without a trailing slash, for example:
42+
// shopName: "gatsby-shop.com",
4043
shopName: "gatsby-source-shopify-test-shop",
4144

4245
// An API access token to your Shopify shop. This is required.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
const { createClient } = require(`../create-client`)
2+
3+
describe(`create-client`, () => {
4+
it(`Allows a domain as shop name`, () => {
5+
expect(createClient(`my-shop.com`, `token`).url).toEqual(
6+
expect.not.stringContaining(`myshopify.com`)
7+
)
8+
})
9+
10+
it(`Allows a non-domain shop name`, () => {
11+
expect(createClient(`my-shop`, `token`).url).toEqual(
12+
expect.stringContaining(`myshopify.com`)
13+
)
14+
})
15+
})

packages/gatsby-source-shopify/src/create-client.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,16 @@ import { GraphQLClient } from "graphql-request"
22
/**
33
* Create a Shopify Storefront GraphQL client for the provided name and token.
44
*/
5-
export const createClient = (shopName, accessToken) =>
6-
new GraphQLClient(`https://${shopName}.myshopify.com/api/graphql`, {
5+
export const createClient = (shopName, accessToken) => {
6+
let url
7+
if (shopName.includes(`.`)) {
8+
url = `https://${shopName}/api/graphql`
9+
} else {
10+
url = `https://${shopName}.myshopify.com/api/graphql`
11+
}
12+
return new GraphQLClient(url, {
713
headers: {
814
"X-Shopify-Storefront-Access-Token": accessToken,
915
},
1016
})
17+
}

0 commit comments

Comments
 (0)