From f010a6869af5ec0cf3cb6228c26ada81f79ca425 Mon Sep 17 00:00:00 2001 From: Linus Flood Date: Thu, 27 Mar 2025 12:54:07 +0000 Subject: [PATCH] Merged in fix/preview-cache (pull request #1655) feat(contentstack): use no cache if preview * feat(contentstack): use no cache if preview Approved-by: Anton Gunnarsson --- apps/scandic-web/lib/graphql/request.ts | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/apps/scandic-web/lib/graphql/request.ts b/apps/scandic-web/lib/graphql/request.ts index b7e036c2c..eb2c40a12 100644 --- a/apps/scandic-web/lib/graphql/request.ts +++ b/apps/scandic-web/lib/graphql/request.ts @@ -21,12 +21,22 @@ export async function request( ttl: CacheTime } ): Promise> { - const doCall = () => internalRequest(query, variables) + const shouldUsePreview = variables?.uid + ? isPreviewByUid(variables.uid) + : false + + const doCall = () => internalRequest(query, shouldUsePreview, variables) + if (!cacheOptions) { console.warn("[NO CACHE] for query", query) return doCall() } + if (shouldUsePreview) { + console.log("[NO CACHE] [PREVIEW] for query", query) + return doCall() + } + const cacheKey: string = Array.isArray(cacheOptions.key) ? cacheOptions.key.join("_") : cacheOptions.key @@ -37,11 +47,9 @@ export async function request( function internalRequest( query: string | DocumentNode, + shouldUsePreview: boolean, variables?: Record ): Promise> { - const shouldUsePreview = variables?.uid - ? isPreviewByUid(variables.uid) - : false const previewHash = getPreviewHash() const cmsUrl = shouldUsePreview ? env.CMS_PREVIEW_URL : env.CMS_URL