Skip to content

fix: respect excludeContentTypes across instances sharing a type_prefix - #279

Merged
abhishek-ezhava-cstk merged 2 commits into
masterfrom
fix/DX-9470-exclude-content-types-shared-cache
Aug 4, 2026
Merged

fix: respect excludeContentTypes across instances sharing a type_prefix#279
abhishek-ezhava-cstk merged 2 commits into
masterfrom
fix/DX-9470-exclude-content-types-shared-cache

Conversation

@abhishek-ezhava-cstk

Copy link
Copy Markdown
Contributor

Summary

Fixes DX-9470. A customer reported that excludeContentTypes is silently ignored when two gatsby-source-contentstack instances share the same type_prefix (e.g. a main stack + a shared/publisher stack merged into one schema). Customer opened PR #277 with a fix; per policy we don't merge code from an external fork directly, so this reimplements the fix ourselves after verifying the root cause and the intended behavior independently.

Root cause: Gatsby's plugin cache is shared across all instances of this plugin, not namespaced per instance/options. The content-types list was cached under a bare type_prefix key (unlike most other cache keys in this codebase, which already suffix with api_key). When two instances share type_prefix, whichever instance's createSchemaCustomization runs last overwrites that key for both, so the instance with excludeContentTypes reads back the other instance's unfiltered list.

Fix:

  • Namespace the content-types cache key by api_key at all 5 read/write sites (create-schema-customization.js, create-resolvers.js, entry-data.js x2, source-node.js) — this is the root-cause fix, not a re-filter patch at a couple of call sites.
  • contenttype-data.js: excluded content types no longer sneak back in via a reference field on an included content type (FetchUnspecifiedContentTypes's referred-content-types lookup wasn't filtered by excludeContentTypes).
  • Dependency hygiene: patched fast-uri, brace-expansion, postcss to their fixed versions, and deduped @semantic-release/npm to remove a duplicate older/vulnerable branch pulled in by semantic-release's own dependency tree.

Test plan

  • New unit test (src/tests/exclude-content-types.test.js): two configs sharing a type_prefix with different api_keys and different excludeContentTypes no longer collide; referred-content-types filter verified in isolation.
  • npm test — full suite passes.
  • Live end-to-end verification against two real Contentstack stacks sharing a type_prefix, each with its own excludeContentTypes, using the contentstack-gatsby-starter-app:
    • Ground-truth entry counts pulled directly from each stack's CDA.
    • After the fix, the merged GraphQL type only contains the non-excluded stack's entries — verified exact match, no cross-stack leakage.
    • Added a real reference field (included type → excluded type) with live data — confirmed the excluded type's schema type name still appears (expected, required for the reference field's GraphQL type), but zero real entries/nodes are sourced for it, and the reference resolves empty.
    • Full Playwright e2e suite (28 tests) passes with both single-stack and two-stack configs.

Gatsby's plugin cache is shared across all instances of this plugin,
not namespaced per instance. When two stacks share the same
type_prefix (to merge into one schema), whichever instance's
createSchemaCustomization runs last overwrote the cached content-types
list for both, silently dropping the other instance's
excludeContentTypes.
Namespace the content-types cache key by api_key everywhere it's
read/written (create-schema-customization, create-resolvers,
entry-data x2, source-node), and stop excluded-but-referenced content
types from sneaking back in via reference-field resolution in
contenttype-data's FetchUnspecifiedContentTypes.
Fixes DX-9470.
…-release/npm
- fast-uri -> 3.1.5 (SNYK-JS-FASTURI-18506908)
- brace-expansion -> 5.0.9 (SNYK-JS-BRACEEXPANSION-18512280)
- postcss -> 8.5.23 (SNYK-JS-POSTCSS-18512282)
- @semantic-release/npm forced to 13.1.5 everywhere, removing the
duplicate older 12.0.2 branch (and its vulnerable bundled npm/tar)
that semantic-release's own dependency tree still pulled in
nanoid and react-dev-utils remain unfixed: nanoid's fix is ESM-only
and breaks postcss's CJS require; react-dev-utils@12.0.1 is gatsby's
own dependency and the latest available stable release.
@snyk-io

snyk-ioBot commented Aug 4, 2026

Copy link
Copy Markdown

Snyk checks have passed. No issues have been found so far.

StatusScan Engine Critical High Medium LowTotal (0)
Open Source Security0000 0 issues
Licenses0000 0 issues
Code Security0000 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

@github-actions

Copy link
Copy Markdown

🔒 Security Scan Results

ℹ️ Note: Only vulnerabilities with available fixes (upgrades or patches) are counted toward thresholds.

Check TypeCount (with fixes)Without fixesThresholdResult
🔴 Critical Severity0110✅ Passed
🟠 High Severity0225✅ Passed
🟡 Medium Severity041500✅ Passed
🔵 Low Severity001000✅ Passed

⏱️ SLA Breach Summary

✅ No SLA breaches detected. All vulnerabilities are within acceptable time thresholds.

SeverityBreaches (with fixes)Breaches (no fixes)SLA Threshold (with/no fixes)Status
🔴 Critical0015 / 30 days✅ Passed
🟠 High0030 / 120 days✅ Passed
🟡 Medium0090 / 365 days✅ Passed
🔵 Low00180 / 365 days✅ Passed

ℹ️ Vulnerabilities Without Available Fixes (Informational Only)

The following vulnerabilities were detected but do not have fixes available (no upgrade or patch). These are excluded from failure thresholds:

  • Critical without fixes: 1
  • High without fixes: 2
  • Medium without fixes: 41
  • Low without fixes: 0

✅ BUILD PASSED - All security checks passed

CopilotAI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes a multi-instance caching collision in gatsby-source-contentstack where excludeContentTypes could be ignored when two plugin instances share the same type_prefix, by namespacing the cached content-types list with api_key. It also tightens excludeContentTypes behavior for referred content types and updates dependency overrides/lockfile accordingly.

Changes:

  • Namespace the cached content-types list key as ${type_prefix}_${api_key} across all read/write sites to prevent cross-instance cache overwrites.
  • Ensure referred content types fetched via reference fields don’t reintroduce content types listed in excludeContentTypes.
  • Add unit coverage for the cache isolation + referred-content-types filtering, and update dependency overrides / lockfile.

Reviewed changes

Copilot reviewed 8 out of 10 changed files in this pull request and generated 1 comment.

Show a summary per file
FileDescription
src/create-schema-customization.jsWrites the content-types cache entry using a key that includes api_key.
src/create-resolvers.jsReads content types from the namespaced cache key.
src/entry-data.jsReads content types from the namespaced cache key in both entry-fetch flows.
src/source-node.jsReads content types from the namespaced cache key during sourcing.
src/contenttype-data.jsFilters referred content types using excludeContentTypes.
src/tests/exclude-content-types.test.jsAdds unit tests for cache key isolation and referred-type filtering.
tests/exclude-content-types.test.jsCompiled/built copy of the new unit tests.
package.jsonBumps version and updates overrides (incl. patched dependency versions / dedupe).
package-lock.jsonLockfile updates reflecting the dependency/override changes.
.talismanrcAdds checksum allowlists for newly changed files (flagged in review).
Files not reviewed (1)
  • tests/exclude-content-types.test.js: Generated file
Suppressed comments (1)

.talismanrc:13

  • .talismanrc: Checksum allowlists for test files also bypass Talisman scanning for those files when the checksum matches. If these were added due to a false positive, it’s safer to address the triggering content or apply a narrowly-scoped ignore rather than allowlisting entire files by checksum.
- filename: src/tests/exclude-content-types.test.js
checksum: 4acbcfad3da0e20b6150ce47054668b629db9ddd8362d3a96fadb3a770a0f5a4
- filename: tests/exclude-content-types.test.js
checksum: 907f5d9ee53a42774f4ecbc361dc6b2cd6f278ed7dbf6dd6cf071d4f478a4b67

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread.talismanrc
@abhishek-ezhava-cstk
abhishek-ezhava-cstk merged commit eae4b4b into masterAug 4, 2026
9 checks passed
@abhishek-ezhava-cstk
abhishek-ezhava-cstk deleted the fix/DX-9470-exclude-content-types-shared-cache branch August 4, 2026 10:54
Sign up for freeto 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

@abhishek-ezhava-cstk@netrajpatel@cs-raj