Skip to content

Commit

Permalink
[sitecore-jss] Fix custom retryStrategy (#1749)
Browse files Browse the repository at this point in the history
* fix retryStrategy

* update changelog

* update changelog-2

* update changelog-3

* add to error pages service
  • Loading branch information
addy-pathania authored Feb 27, 2024
1 parent 00c9a8b commit 594f73f
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 2 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ Our versioning strategy is as follows:
* `[templates/nextjs-sxa]` Fix feature `show Grid column` in Experience Editor. ([#1704](https://github.com/Sitecore/jss/pull/1704))
* `[sitecore-jss-nextjs] [templates/nextjs-xmcloud]` SDK initialization rejections are now correctly handled. Errors should no longer occur after getSDK() promises resolve when they shouldn't (for example, getting Events SDK in development environment) ([#1712](https://github.com/Sitecore/jss/pull/1712) [#1715](https://github.com/Sitecore/jss/pull/1715) [#1716](https://github.com/Sitecore/jss/pull/1716))
* `[sitecore-jss-nextjs]` Fix redirects middleware for working with absolute url where is using site language context ([#1727](https://github.com/Sitecore/jss/pull/1727)) ([#1737](https://github.com/Sitecore/jss/pull/1737))
* `[sitecore-jss]` Retry policy to handle transient network errors. Users can pass `retryStrategy` to configure custom retry config to the services. They can customize the error codes and the number of retries. It consist of two functions shouldRetry and getDelay. To determine the back-off time, we employ an exponential strategy with a default factor of 2.([#1731](https://github.com/Sitecore/jss/pull/1731)) ([#1733](https://github.com/Sitecore/jss/pull/1733)) ([#1738](https://github.com/Sitecore/jss/pull/1738))
* `[sitecore-jss]` Enable the Layout and dictionary service to use custom `retryStrategy`. ([#1749](https://github.com/Sitecore/jss/pull/1749))

### 🛠 Breaking Changes

Expand Down
2 changes: 2 additions & 0 deletions packages/sitecore-jss/src/i18n/graphql-dictionary-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,13 +178,15 @@ export class GraphQLDictionaryService extends DictionaryServiceBase {
return this.options.clientFactory({
debugger: debug.dictionary,
retries: this.options.retries,
retryStrategy: this.options.retryStrategy,
});
}

return new GraphQLRequestClient(this.options.endpoint, {
apiKey: this.options.apiKey,
debugger: debug.dictionary,
retries: this.options.retries,
retryStrategy: this.options.retryStrategy,
});
}
}
2 changes: 2 additions & 0 deletions packages/sitecore-jss/src/layout/graphql-layout-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,13 +102,15 @@ export class GraphQLLayoutService extends LayoutServiceBase {
return this.serviceConfig.clientFactory({
debugger: debug.layout,
retries: this.serviceConfig.retries,
retryStrategy: this.serviceConfig.retryStrategy,
});
}

return new GraphQLRequestClient(this.serviceConfig.endpoint, {
apiKey: this.serviceConfig.apiKey,
debugger: debug.layout,
retries: this.serviceConfig.retries,
retryStrategy: this.serviceConfig.retryStrategy,
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const defaultQuery = /* GraphQL */ `
`;

export interface GraphQLErrorPagesServiceConfig
extends Pick<GraphQLRequestClientConfig, 'retries'> {
extends Pick<GraphQLRequestClientConfig, 'retries' | 'retryStrategy'> {
/**
* Your Graphql endpoint
* @deprecated use @param clientFactory property instead
Expand Down Expand Up @@ -124,13 +124,15 @@ export class GraphQLErrorPagesService {
return this.options.clientFactory({
debugger: debug.errorpages,
retries: this.options.retries,
retryStrategy: this.options.retryStrategy,
});
}

return new GraphQLRequestClient(this.options.endpoint, {
apiKey: this.options.apiKey,
debugger: debug.errorpages,
retries: this.options.retries,
retryStrategy: this.options.retryStrategy,
});
}
}

0 comments on commit 594f73f

Please sign in to comment.