Skip to content

Commit d0e0c49

Browse files
feat(gatsby-source-shopify): Add apiVersion option (#37605)
Co-authored-by: LekoArts <[email protected]>
1 parent af0c983 commit d0e0c49

File tree

4 files changed

+13
-3
lines changed

4 files changed

+13
-3
lines changed

packages/gatsby-source-shopify/README.md

+4
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,10 @@ Not set by default. If set to a string (example `My Sales Channel`), only produc
170170
171171
💡 Note: The `salesChannel` plugin option defaults to the value of `process.env.GATBSY_SHOPIFY_SALES_CHANNEL`. If that value is not set the plugin will source only objects that are published to the `online store` sales channel.
172172
173+
`apiVersion: string`
174+
175+
The API version that should be used. More information: https://shopify.dev/docs/api/usage/versioning.
176+
173177
## Images
174178
175179
You have two options for displaying Shopify images in your Gatsby site. The default option is to use the Shopify CDN along with [gatsby-plugin-image](https://www.gatsbyjs.com/plugins/gatsby-plugin-image/), but you can also opt-in to downloading the images as part of the build process. Your choice will result in differences to the schema. Both options are explained below.

packages/gatsby-source-shopify/src/clients.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const MAX_BACKOFF_MILLISECONDS = 60000
99
export function createGraphqlClient(
1010
options: IShopifyPluginOptions
1111
): IGraphQLClient {
12-
const url = `https://${options.storeUrl}/admin/api/2021-07/graphql.json`
12+
const url = `https://${options.storeUrl}/admin/api/${options.apiVersion}/graphql.json`
1313

1414
async function graphqlFetch<T>(
1515
query: string,
@@ -46,7 +46,7 @@ export function createGraphqlClient(
4646
}
4747

4848
export function createRestClient(options: IShopifyPluginOptions): IRestClient {
49-
const baseUrl = `https://${options.storeUrl}/admin/api/2021-01`
49+
const baseUrl = `https://${options.storeUrl}/admin/api/${options.apiVersion}`
5050

5151
async function shopifyFetch(
5252
path: string,

packages/gatsby-source-shopify/src/plugin-options-schema.ts

+5
Original file line numberDiff line numberDiff line change
@@ -42,5 +42,10 @@ export function pluginOptionsSchema({ Joi }: PluginOptionsSchemaArgs): unknown {
4242
.description(
4343
`Not set by default. If set to a string (example \`MyStore\`) node names will be \`allMyStoreShopifyProducts\` instead of \`allShopifyProducts\``
4444
),
45+
apiVersion: Joi.string()
46+
.default(`2022-04`)
47+
.description(
48+
`The API version that should be used. More information: https://shopify.dev/docs/api/usage/versioning`
49+
),
4550
})
4651
}

packages/gatsby-source-shopify/types/interface.d.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,8 @@ interface IShopifyPluginOptions {
147147
shopifyConnections: Array<string>
148148
typePrefix: string
149149
salesChannel: string
150-
prioritize?: boolean
150+
prioritize?: boolean,
151+
apiVersion: string
151152
}
152153

153154
interface IGraphQLClient {

0 commit comments

Comments
 (0)