When working with Gatsby and Drupal, it's essential to ensure that your website's content appears exactly as intended, even when dealing with unpublished draft content. But how can you achieve this without compromising your development process?
In this blog post, we'll unveil a simple yet powerful technique to fetch and display draft nodes using Gatsby seamlessly.
Using NODE_ENV to filter nodes
Using this simple code example, you can include nodes on Draft state only in development "gatsby develop".
This code sets a value to the status constant based on the process.env.NODE_ENV value and then uses that value to fetch Published nodes on production and Draft + Published nodes while running in development mode.
The objective of fetching only published content on production is to hide those nodes while executing the build process and avoid deploying unpublished content.
Efficiently managing content visibility during the development process is crucial for any Gatsby and Drupal project. Using our code example, you can effortlessly include draft nodes only when running in development mode, ensuring a crystal-clear preview of your unpublished content. With this technique, you'll control what is displayed in production while seamlessly testing and refining your website's user experience. Unlock the power of Gatsby and Drupal while keeping unpublished content under wraps, and propel your development workflow to new heights.