How to Generate a Complete Sitemap for All Dynamic URLs in a Next.js Application with GraphQL?

65 Views Asked by At

In my Next.js application with GraphQL, I am creating a sitemap. All URLs on my site have a generated sitemap. However, there is a problem with dynamically generating a sitemap for URLs that come from the API /recipes/:slug.

For some reason, Next.js only generates sitemaps for 48 recipes in my application. I have 10,000 recipes. How to generate a sitemap in Next.js for all dynamic URLs.

I tried to fetch slugs using ApolloClient directly in the next-sitemap.config.js file, but the sitemap still only generates for 48 recipes. All other URLs on my site have a sitemap.

Description of the Problem:

I am developing a sitemap for my Next.js application, which utilizes GraphQL. This application features numerous URLs, including a set of dynamic URLs derived from an API endpoint, specifically /recipes/:slug. The challenge arises with the dynamic generation of the sitemap for these URLs. Despite having a total of 10,000 recipes, Next.js is only generating sitemap entries for 48 of them.

My approach to addressing this issue involved fetching slugs using ApolloClient within the next-sitemap.config.js file. However, this method has not resolved the issue, as the sitemap continues to only include 48 recipes, ignoring the vast majority of the URLs. It is important to note that this problem is exclusive to the dynamic URLs from the /recipes/:slug API endpoint; all other URLs on the site are successfully incorporated into the sitemap. The primary goal is to find a solution that allows for the successful generation of sitemap entries for all 10,000 dynamic recipe URLs.

module.exports = {
  siteUrl: "MY_WEB_URL",
  generateRobotsTxt: true,
};
0

There are 0 best solutions below