Enable retries for requests to the SitecoreAI Experience Edge GraphQL endpoint
The Experience Edge GraphQL endpoint in SitecoreAI is rate-limited, meaning there is a limit on the number of requests that can be made within a specific time frame (currently 80 requests/second). When building or deploying a large Next.js application with static generation (SSG) enabled, you might hit the limitation, and the build process will fail. At build time, the Next.js application configured to use GraphQL sends requests to the endpoint through multiple services.
To successfully generate the production code for a large website, you can enable retries for the GraphQL client in your Next.js application.
You can configure a specific number of retries globally or per service.
Next.js JSS applications use the GRAPH_QL_SERVICE_RETRIES environment variable for setting the number of GraphQL request retries for all services that use the GraphQL endpoint (Layout, Dictionary, and Error Page services). By default, the value of this environment variable is 0.
To enable request retries:
-
Update the value of the
GRAPH_QL_SERVICE_RETRIESenvironment variable to a positive integer.Depending on your deployment practices and setup, you might need to update the variable's value in multiple locations, such as your Next.js application's
.envfile(s), your deployment service, pipelines, and so on.
If you need to specify a different number of retries for each service, you can change the value of the service's retries option or define custom environment variables for each service.
Depending on which approach you prefer, replace the existing retries value with a hard-coded positive integer or the environment variable name in the following files:
-
For the Layout Service, in the
src/lib/layout-service-factory.tsfile. -
For the Dictionary Service, in the
src/lib/dictionary-service-factory.tsfile. -
For the Error Page Service, in the
src/pages/404.tsxandsrc/pages/500.tsxfiles.
If you define custom environment variables, for example, GRAPH_QL_LAYOUT_SERVICE_RETRIES, you must remember to add the variables to SitecoreAI, your deployment service, pipelines, and so on.
For additional information on working with environment variables in SitecoreAI, refer to: