feat(SW-285): add support for tags
This commit is contained in:
@@ -4,7 +4,6 @@ import { request } from "@/lib/graphql/request"
|
||||
import { notFound } from "@/server/errors/trpc"
|
||||
import { contentstackExtendedProcedureUID, router } from "@/server/trpc"
|
||||
|
||||
import { generateTag } from "@/utils/generateTag"
|
||||
import { makeImageVaultImage } from "@/utils/imageVault"
|
||||
import { removeMultipleSlashes } from "@/utils/url"
|
||||
|
||||
@@ -15,6 +14,12 @@ import {
|
||||
ContentPageDataRaw,
|
||||
validateContentPageSchema,
|
||||
} from "./output"
|
||||
import {
|
||||
fetchContentPageRefs,
|
||||
generatePageTags,
|
||||
getContentPageCounter,
|
||||
validateContentPageRefs,
|
||||
} from "./utils"
|
||||
|
||||
import { ContentBlocksTypenameEnum } from "@/types/components/content/enums"
|
||||
import {
|
||||
@@ -26,13 +31,31 @@ export const contentPageQueryRouter = router({
|
||||
get: contentstackExtendedProcedureUID.query(async ({ ctx }) => {
|
||||
const { lang, uid } = ctx
|
||||
|
||||
// TODO: Refs request should be done when adding more data to this query
|
||||
// which has references to other pages.
|
||||
const cleanedRefsData = await fetchContentPageRefs(lang, uid)
|
||||
const validatedRefsData = validateContentPageRefs(
|
||||
cleanedRefsData,
|
||||
lang,
|
||||
uid
|
||||
)
|
||||
const tags = generatePageTags(validatedRefsData, lang)
|
||||
|
||||
getContentPageCounter.add(1, { lang, uid })
|
||||
console.info(
|
||||
"contentstack.contentPage start",
|
||||
JSON.stringify({
|
||||
query: { lang, uid },
|
||||
})
|
||||
)
|
||||
|
||||
const response = await request<ContentPageDataRaw>(
|
||||
GetContentPage,
|
||||
{ locale: lang, uid },
|
||||
{ cache: "force-cache", next: { tags: [generateTag(lang, uid)] } }
|
||||
{
|
||||
cache: "force-cache",
|
||||
next: {
|
||||
tags,
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
const { content_page } = removeEmptyObjects(response.data)
|
||||
|
||||
Reference in New Issue
Block a user