From 4fb1a4dbb13813357ddf78dafba28b2e3f58072b Mon Sep 17 00:00:00 2001 From: Shashank Agrawal Date: Tue, 7 Mar 2023 17:32:03 +0530 Subject: [PATCH] feat: Global configuration to set default retries --- docs/reference/shopifyApi.md | 7 +++++++ lib/base-types.ts | 1 + lib/clients/http_client/http_client.ts | 5 +++-- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/docs/reference/shopifyApi.md b/docs/reference/shopifyApi.md index cbe88a525..98469b105 100644 --- a/docs/reference/shopifyApi.md +++ b/docs/reference/shopifyApi.md @@ -18,6 +18,7 @@ const shopify = shopifyApi({ apiVersion: ApiVersion.July22, isEmbeddedApp: true, isCustomStoreApp: false, + defaultRetries: 1, userAgentPrefix: 'Custom prefix', privateAppStorefrontAccessToken: 'PrivateAccessToken', customShopDomains: ['*.my-custom-domain.io'], @@ -87,6 +88,12 @@ Whether your app will run within the Shopify Admin. Learn more about embedded ap Whether you are building a private app for a store. +### defaultRetries + +`number` | Defaults to `1` + +Set default retry attempts for Rest & GraphQL client. + ### userAgentPrefix `string` | Defaults to `undefined` diff --git a/lib/base-types.ts b/lib/base-types.ts index 77a76524a..41de1d40f 100644 --- a/lib/base-types.ts +++ b/lib/base-types.ts @@ -15,6 +15,7 @@ export interface ConfigParams { apiVersion: ApiVersion; isEmbeddedApp: boolean; isCustomStoreApp?: boolean; + defaultRetries?: number; userAgentPrefix?: string; privateAppStorefrontAccessToken?: string; customShopDomains?: (RegExp | string)[]; diff --git a/lib/clients/http_client/http_client.ts b/lib/clients/http_client/http_client.ts index cce5783ad..f86b48593 100644 --- a/lib/clients/http_client/http_client.ts +++ b/lib/clients/http_client/http_client.ts @@ -84,7 +84,8 @@ export class HttpClient { protected async request( params: RequestParams, ): Promise> { - const maxTries = params.tries ? params.tries : 1; + const config = this.httpClass().config; + const maxTries = params.tries ? params.tries : (config.defaultRetries ?? 1); if (maxTries <= 0) { throw new ShopifyErrors.HttpRequestError( `Number of tries must be >= 0, got ${maxTries}`, @@ -93,7 +94,7 @@ export class HttpClient { let userAgent = `${LIBRARY_NAME} v${SHOPIFY_API_LIBRARY_VERSION} | ${abstractRuntimeString()}`; - if (this.httpClass().config.userAgentPrefix) { + if (config.userAgentPrefix) { userAgent = `${this.httpClass().config.userAgentPrefix} | ${userAgent}`; }