Skip to content

Commit

Permalink
Extend retrier to ErrorPagesService and make it configurable through env
Browse files Browse the repository at this point in the history
  • Loading branch information
art-alexeyenko committed Sep 25, 2023
1 parent d8fa093 commit eaf805c
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ export const getStaticProps: GetStaticProps = async (context) => {
apiKey: config.sitecoreApiKey,
siteName: site.name,
language: context.locale || config.defaultLanguage,
retries:
(process.env.GRAPH_QL_SERVICE_RETRIES &&
parseInt(process.env.GRAPH_QL_SERVICE_RETRIES, 10)) ||
0,
});
let resultErrorPages: ErrorPages | null = null;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ export const getStaticProps: GetStaticProps = async (context) => {
apiKey: config.sitecoreApiKey,
siteName: site.name,
language: context.locale || context.defaultLocale || config.defaultLanguage,
retries:
(process.env.GRAPH_QL_SERVICE_RETRIES &&
parseInt(process.env.GRAPH_QL_SERVICE_RETRIES, 10)) ||
0,
});
let resultErrorPages: ErrorPages | null = null;

Expand Down
3 changes: 3 additions & 0 deletions packages/create-sitecore-jss/src/templates/nextjs/.env
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ JSS_APP_NAME=
# Your default app language.
DEFAULT_LANGUAGE=

# How many times should GraphQL Layout, Dictionary and ErrorPages services retry a fetch when endpoint rate limit is reached
GRAPH_QL_SERVICE_RETRIES=0

# The way in which layout and dictionary data is fetched from Sitecore
FETCH_WITH=<%- fetchWith %>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ export class DictionaryServiceFactory {
It will only try the request once by default.
retries: 'number'
*/
retries:
(process.env.GRAPH_QL_SERVICE_RETRIES &&
parseInt(process.env.GRAPH_QL_SERVICE_RETRIES, 10)) ||
0,
})
: new RestDictionaryService({
apiHost: config.sitecoreApiHost,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ export class LayoutServiceFactory {
It will only try the request once by default.
retries: 'number'
*/
retries:
(process.env.GRAPH_QL_SERVICE_RETRIES &&
parseInt(process.env.GRAPH_QL_SERVICE_RETRIES, 10)) ||
0,
})
: new RestLayoutService({
apiHost: config.sitecoreApiHost,
Expand Down
5 changes: 3 additions & 2 deletions packages/sitecore-jss/src/site/graphql-error-pages-service.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { GraphQLClient, GraphQLRequestClient } from '../graphql';
import { GraphQLClient, GraphQLRequestClient, GraphQLRequestClientConfig } from '../graphql';
import { siteNameError } from '../constants';
import debug from '../debug';
import { LayoutServiceData } from '../layout';
Expand All @@ -23,7 +23,7 @@ const defaultQuery = /* GraphQL */ `
}
`;

export type GraphQLErrorPagesServiceConfig = {
export interface GraphQLErrorPagesServiceConfig extends Pick<GraphQLRequestClientConfig, 'retries'> {
/**
* Your Graphql endpoint
*/
Expand Down Expand Up @@ -110,6 +110,7 @@ export class GraphQLErrorPagesService {
return new GraphQLRequestClient(this.options.endpoint, {
apiKey: this.options.apiKey,
debugger: debug.errorpages,
retries: this.options.retries,
});
}
}

0 comments on commit eaf805c

Please sign in to comment.