export query v1 support#122
Draft
shafeeqd959 wants to merge 2 commits intodevelopmentfrom
Draft
Conversation
🔒 Security Scan Results
⏱️ SLA Breach Summary
✅ BUILD PASSED - All security checks passed |
🔒 Security Scan Results
⏱️ SLA Breach Summary
✅ BUILD PASSED - All security checks passed |
netrajpatel
approved these changes
Apr 30, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Aligns @contentstack/cli-cm-export-query with CLI v1 export layout and utilities, and fixes missing entries when multiple content-types export runs overwrite content_types/schema.json.
Motivation
v1 on-disk contract — Content types are aggregated in content_types/schema.json; global fields stay on the existing global_fields layout (globalfields.json / per-file), not a single CT-style schema.json for GFs.
Utilities — Current @contentstack/cli-utilities does not expose loadChalk / readContentTypeSchemas in the same way; the plugin should not depend on them.
Entries gap — cli-cm-export writes schema.json with only the content types from the latest content-types run. Query export invokes that module several times (query + closure), so schema.json could drop earlier types (e.g. queried test) while {uid}.json files remained. The entries module only reads schema.json, so entries for those types were skipped.
Changes
CLI v1 / query plan (query-v1.md)
export-query.ts — Removed loadChalk import and await loadChalk() from run().
read-content-type-schemas.ts (new) —
readContentTypesFromExportDir — reads …/content_types/schema.json into any[].
readGlobalFieldSchemasFromDir — globalfields.json first, then legacy per-directory / loose JSON under global_fields/.
query-executor.ts — expandSchemaClosure uses the above for CT vs GF reads instead of utilities’ readContentTypeSchemas.
dependency-resolver.ts — Disk fallback loads CTs via readContentTypesFromExportDir only; removed unused utilities imports.
config/index.ts — contentVersion set to 1 for this branch.
Fix: full CT list for entries / closure
rebuildContentTypesSchemaJson — Rebuilds content_types/schema.json from every per-UID *.json in that folder (excluding schema.json), deduped by uid.
module-exporter.ts — After each successful content-types export, calls rebuildContentTypesSchemaJson for {exportDir}/{branch}/content_types so the aggregate matches all on-disk CT files before entries (and matches what closure reads from disk).
Tests
query-executor.test.ts — Stubs readContentTypesFromExportDir / readGlobalFieldSchemasFromDir instead of non-existent content-type-utils.
dependency-resolver.test.ts — contentVersion: 1, temp-dir coverage for disk fallback from schema.json, and related imports.
read-content-type-schemas.test.ts — Merge, dedupe-by-uid, and invalid-file behavior for rebuildContentTypesSchemaJson.
How to verify
Run a query export that pulls a CT and then pulls referenced CTs (e.g. title filter on a type that references others).
Confirm content_types/schema.json lists all UIDs that have content_types/.json.
Confirm entries// exists for each of those types (including the originally queried one).
Risk / notes
Order of files on disk — Rebuild uses readdir; duplicate uid from multiple files resolves to one winner (last write wins in the current Map iteration order). Normal export layout is one file per uid.
Upstream — Longer term, merging in @contentstack/cli-cm-export would avoid needing this rebuild in the plugin; until then this keeps v1 query export consistent.