Skip to content

fix: avoid errors when excluding content types with multiple sources … #246

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 14 commits into
base: staging
Choose a base branch
from

Conversation

ccarrascal
Copy link

…using the same schema

PR to fix errors happening while building a site importing content from two different stacks.

Our schema is the same in both stacks and we just want to combine the content of both, but we need to exclude some content types from the shared stack that we don't want to import.

We are using this setup in our gatsby-config file:

// Shared content stack
{
    resolve: "gatsby-source-contentstack",
    options: {
        api_key: process.env.SHARED_CONTENTSTACK_API_KEY,
        delivery_token: process.env.SHARED_CONTENTSTACK_DELIVERY_TOKEN,
        environment: process.env.GATSBY_CONTENTSTACK_ENVIRONMENT,
        cdn: "https://eu-cdn.contentstack.com/v3",
        disableMandatoryFields: "true",
        downloadImages: "false",
        ...{ locales: process.env.GATSBY_LOCALES?.split(",").map((s) => s.trim()) },
        excludeContentTypes: ["shell"],
    },
},
// Primary content stack
{
    resolve: "gatsby-source-contentstack",
    options: {
        api_key: process.env.CONTENTSTACK_API_KEY,
        delivery_token: process.env.CONTENTSTACK_DELIVERY_TOKEN,
        environment: process.env.GATSBY_CONTENTSTACK_ENVIRONMENT,
        cdn: "https://eu-cdn.contentstack.com/v3",
        enableSchemaGeneration: "true",
        disableMandatoryFields: "true",
        downloadImages: "false",
        ...{ locales: process.env.GATSBY_LOCALES?.split(",").map((s) => s.trim()) },
    },
},

The first instance (shared content) is excluding some content types with excludeContentTypes: ["shell"]

This is creating errors as the contentType variable is empty because there is no match in contentTypesMap[item.content_type_uid]

The idea is to avoid creating the node if the content type uid is in the list of excluded content types, or it just null.

@ccarrascal ccarrascal requested a review from a team as a code owner May 27, 2025 14:40
@abhishek305 abhishek305 changed the base branch from master to staging June 23, 2025 14:27
Copy link
Contributor

@abhishek305 abhishek305 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ccarrascal Thanks for the update! Please verify the suggested feedback—everything else looks good to me.
Once approved, we’ll proceed to merge the changes into staging and validate the functionality there.

@ccarrascal ccarrascal force-pushed the fix/errors-with-excluded-content-types branch from be3011f to 373c43b Compare June 23, 2025 16:40
@abhishek305
Copy link
Contributor

abhishek305 commented Jun 27, 2025

@ccarrascal Just revisiting the issue for clarity—while testing the changes, could you please share the exact error you were encountering during node generation? It would help in documenting and validating the fix better.

Could you also help me with the steps to reproduce ?
As I am currently trying to reproduce the issue with the below config, where I am excluding the "footer" content-type with the PR changes still the build is breaking.

      resolve: "gatsby-source-contentstack",
      options: {
        api_key: CONTENTSTACK_API_KEY,
        delivery_token: CONTENTSTACK_DELIVERY_TOKEN,
        environment: CONTENTSTACK_ENVIRONMENT,
        branch: CONTENTSTACK_BRANCH ? CONTENTSTACK_BRANCH : "main",
        cdn: `https://cdn.contentstack.io/v3`,
        // Specify whether to convert RTE Json to HTML
        jsonRteToHtml: true,
        // Optional: expediteBuild set this to either true or false
        expediteBuild: true,
        // Optional: Specify true if you want to generate custom schema
        enableSchemaGeneration: true,
        // Optional: Specify a different prefix for types. This is useful in cases where you have multiple instances of the plugin to be connected to different stacks.
        type_prefix: "Contentstack", // (default),
        excludeContentTypes: ["footer"],
      },
    },
    {
      resolve: "gatsby-source-contentstack",
      options: {
        api_key: "key",
        delivery_token: "delivery key",
        environment: "preview",
        branch: CONTENTSTACK_BRANCH ? CONTENTSTACK_BRANCH : "main",
        cdn: `https://cdn.contentstack.io/v3`,
        // Specify whether to convert RTE Json to HTML
        jsonRteToHtml: true,
        // Optional: expediteBuild set this to either true or false
        expediteBuild: true,
        // Optional: Specify true if you want to generate custom schema
        enableSchemaGeneration: true,
        // Optional: Specify a different prefix for types. This is useful in cases where you have multiple instances of the plugin to be connected to different stacks.
        type_prefix: "Contentstack_v2", // (default),
      },
    },

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants