I’m working on a project where I’ve got a headless CMS built with Django as my backend. I want my Gatsby frontend to create pages automatically based on content from the CMS. I’ve set up GraphQL with Graphene to expose the Django data, but I’m stuck on how to fetch the slugs and use them in gatsby-node.js to generate pages.
This code isn’t working as expected. How can I properly fetch the slugs from my CMS and use them to create Gatsby pages? Any tips or best practices for this kind of setup?
hey there! have u considered using gatsby-source-graphql plugin? it can make fetching data from ur django CMS way easier. u could set it up like this in ur gatsby-config.js:
Your approach is on the right track, but there are a few tweaks that could help. First, ensure your GraphQL schema in Django is correctly exposing the data you need. Then, in your gatsby-node.js, add error handling and data validation. Here’s a refined version:
This handles potential errors and ensures each slug is valid before creating a page. Remember to adjust the GraphQL query if your CMS uses a different field name for slugs.