GraphQL Sitemap Service
GraphQLSitemapService fetches the list of site pages using Sitecore's GraphQL API. We commonly use this service in conjuction with
getStaticPaths. Next.js uses the list of pages to fetch data for Static Generation and Export functionality. See getStaticPaths.
In the sample application, in
/src/lib/sitemap-fetcher.ts you can inspect and modify the default SitemapFetcher configuration.
The service comes preconfigured with:
You also have the possibility to specify a
rootItemId. The Sitemap Service needs a root item ID in order to fetch the list of pages for the current app. If
rootItemId is not specified, the service will attempt to figure out the root item for the current JSS app using GraphQL and the app name.
PERFORMANCE TIP: We strongly recommend you to specify a
rootItemIdto avoid a additional GraphQL lookups.
WARNING: Not specifying the
rootItemIdfor the GraphQL Sitemap Service instance can cause errors when using our Next.js SDK in conjuction with SXA integration.
For static export,
fetchExportSitemap. As static export doesn't support multilingual apps, this function accepts one
languageand will only run GraphQL queries for that language.
For static generation, use
fetchSSGSitemap. This function accepts an array of supported
languages. It will include the
localeproperty because the sample application enables i18n by default. It will run GraphQL query for each language.
When you execute
fetchExportSitemap using the
GraphQLSitemapService, the service executes the following steps:
- Fetch the
rootItemIdusing the provided
- Fetch items using
rootItemIdand the provided
- Merge loaded items in the correct format for SSG or static HTML export.
The default GraphQL query used by GraphQL Sitemap Service to fetch items and generate the sitemap can be replaced with a custom query. To do so, extend the
GraphQLSitemapService class, overriding the
fetchSitemap method used internally by