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
This commit is contained in:
@@ -21,12 +21,22 @@ export async function request<T>(
|
||||
ttl: CacheTime
|
||||
}
|
||||
): Promise<Data<T>> {
|
||||
const doCall = () => internalRequest<T>(query, variables)
|
||||
const shouldUsePreview = variables?.uid
|
||||
? isPreviewByUid(variables.uid)
|
||||
: false
|
||||
|
||||
const doCall = () => internalRequest<T>(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<T>(
|
||||
|
||||
function internalRequest<T>(
|
||||
query: string | DocumentNode,
|
||||
shouldUsePreview: boolean,
|
||||
variables?: Record<string, any>
|
||||
): Promise<Data<T>> {
|
||||
const shouldUsePreview = variables?.uid
|
||||
? isPreviewByUid(variables.uid)
|
||||
: false
|
||||
const previewHash = getPreviewHash()
|
||||
const cmsUrl = shouldUsePreview ? env.CMS_PREVIEW_URL : env.CMS_URL
|
||||
|
||||
|
||||
Reference in New Issue
Block a user