From 087924e4c9abb2450197b9805873e0070d55cae7 Mon Sep 17 00:00:00 2001 From: Janusz Paprzycki Date: Wed, 10 Dec 2025 11:46:25 +0100 Subject: [PATCH 1/3] feat: allow cslp meta in fragments --- src/live-preview/resolveCslpMeta.js | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/src/live-preview/resolveCslpMeta.js b/src/live-preview/resolveCslpMeta.js index 90cae36..1f13b62 100644 --- a/src/live-preview/resolveCslpMeta.js +++ b/src/live-preview/resolveCslpMeta.js @@ -21,6 +21,7 @@ export function resolveCslpMeta({ // So, get the correct Selection from query for the current cslp__meta const queryContentTypeSelection = findQuerySelection( info.operation.selectionSet, + info.fragments, fieldNodeValue, fieldNodeLocation ) @@ -52,7 +53,7 @@ export function resolveCslpMeta({ return result; } -function findQuerySelection(selectionSet, value, location, depth = 0) { +function findQuerySelection(selectionSet, fragments, value, location, depth = 0) { // cslp__meta can only be one level deep (or two level deep, see all* case below) // e.g. // query { @@ -64,6 +65,14 @@ function findQuerySelection(selectionSet, value, location, depth = 0) { // cslp__meta // } // } + // allContentstackPage { + // nodes { + // ...PageFragment + // } + // } + // } + // fragment PageFragment on Contentstack_page { + // cslp__meta // } if (depth > 1 || !selectionSet || !selectionSet.selections) { return; @@ -76,15 +85,27 @@ function findQuerySelection(selectionSet, value, location, depth = 0) { ) { return selectionSet } + if (selection.kind === 'FragmentSpread') { + const nestedSelectionSet = findQuerySelection( + fragments[selection.name.value].selectionSet, + fragments, + value, + location, + depth + ); + if (nestedSelectionSet) { + return nestedSelectionSet; + } + } // "nodes" in all* queries will lead to cslp__meta at depth 2 if (selection.name?.value === "nodes") { - const nestedSelectionSet = findQuerySelection(selection.selectionSet, value, location, depth); + const nestedSelectionSet = findQuerySelection(selection.selectionSet, fragments, value, location, depth); if (nestedSelectionSet) { return nestedSelectionSet; } } // search one level deeper for the correct node in this selection - const nestedSelectionSet = findQuerySelection(selection.selectionSet, value, location, depth + 1) + const nestedSelectionSet = findQuerySelection(selection.selectionSet, fragments, value, location, depth + 1) // return when not undefined, meaning the correct selection has been found if (nestedSelectionSet) { return nestedSelectionSet; From 15561f5343813789b244d1e6f838cee67e408ff1 Mon Sep 17 00:00:00 2001 From: Janusz Paprzycki Date: Wed, 10 Dec 2025 12:06:27 +0100 Subject: [PATCH 2/3] feat: improve example --- src/live-preview/resolveCslpMeta.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/live-preview/resolveCslpMeta.js b/src/live-preview/resolveCslpMeta.js index 1f13b62..924e44d 100644 --- a/src/live-preview/resolveCslpMeta.js +++ b/src/live-preview/resolveCslpMeta.js @@ -65,13 +65,16 @@ function findQuerySelection(selectionSet, fragments, value, location, depth = 0) // cslp__meta // } // } - // allContentstackPage { + // page { +// ...PageFragment + // } + // allPage { // nodes { // ...PageFragment // } // } // } - // fragment PageFragment on Contentstack_page { + // fragment PageFragment on Page { // cslp__meta // } if (depth > 1 || !selectionSet || !selectionSet.selections) { From 671755b29a5020cda09e93ecd0fab8dafcb070b9 Mon Sep 17 00:00:00 2001 From: Janusz Paprzycki Date: Wed, 10 Dec 2025 12:09:04 +0100 Subject: [PATCH 3/3] fix: typo --- src/live-preview/resolveCslpMeta.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/live-preview/resolveCslpMeta.js b/src/live-preview/resolveCslpMeta.js index 924e44d..5584566 100644 --- a/src/live-preview/resolveCslpMeta.js +++ b/src/live-preview/resolveCslpMeta.js @@ -66,7 +66,7 @@ function findQuerySelection(selectionSet, fragments, value, location, depth = 0) // } // } // page { -// ...PageFragment + // ...PageFragment // } // allPage { // nodes {