fix: rename retried-wrapped fetch to make caching work again
This commit is contained in:
@@ -45,12 +45,8 @@ const page = z.object({
|
||||
|
||||
export type Page = z.infer<typeof page>
|
||||
|
||||
const metaDataItems = z.object({
|
||||
items: z.array(page),
|
||||
})
|
||||
|
||||
export const validateMyPagesMetaDataContentstackSchema = z.object({
|
||||
all_account_page: metaDataItems,
|
||||
account_page: page,
|
||||
})
|
||||
|
||||
export type GetMyPagesMetaDataData = z.infer<
|
||||
@@ -58,7 +54,7 @@ export type GetMyPagesMetaDataData = z.infer<
|
||||
>
|
||||
|
||||
export const validateLoyaltyPageMetaDataContentstackSchema = z.object({
|
||||
all_loyalty_page: metaDataItems,
|
||||
loyalty_page: page,
|
||||
})
|
||||
|
||||
export type GetLoyaltyPageMetaDataData = z.infer<
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { GetLoyaltyPageMetaData } from "@/lib/graphql/Query/MetaDataLoyaltyPage.graphql"
|
||||
import { GetMyPagesMetaData } from "@/lib/graphql/Query/MetaDataMyPages.graphql"
|
||||
import { contentstackBaseProcedure, router } from "@/server/trpc"
|
||||
import { contentstackExtendedProcedureUID, router } from "@/server/trpc"
|
||||
|
||||
import {
|
||||
type GetLoyaltyPageMetaDataData,
|
||||
@@ -8,7 +8,7 @@ import {
|
||||
validateLoyaltyPageMetaDataContentstackSchema,
|
||||
validateMyPagesMetaDataContentstackSchema,
|
||||
} from "./output"
|
||||
import { getMetaData, getResponse, Variables } from "./utils"
|
||||
import { getMetaData, getResponse, type Variables } from "./utils"
|
||||
|
||||
import { PageTypeEnum } from "@/types/requests/pageType"
|
||||
|
||||
@@ -23,13 +23,13 @@ async function getLoyaltyPageMetaData(variables: Variables) {
|
||||
|
||||
if (!validatedMetaDataData.success) {
|
||||
console.error(
|
||||
`Failed to validate Loyaltypage MetaData Data - (url: ${variables.url})`
|
||||
`Failed to validate Loyaltypage MetaData Data - (uid: ${variables.uid})`
|
||||
)
|
||||
console.error(validatedMetaDataData.error)
|
||||
return null
|
||||
}
|
||||
|
||||
return getMetaData(validatedMetaDataData.data.all_loyalty_page.items[0])
|
||||
return getMetaData(validatedMetaDataData.data.loyalty_page)
|
||||
}
|
||||
|
||||
async function getMyPagesMetaData(variables: Variables) {
|
||||
@@ -43,24 +43,20 @@ async function getMyPagesMetaData(variables: Variables) {
|
||||
|
||||
if (!validatedMetaDataData.success) {
|
||||
console.error(
|
||||
`Failed to validate My Page MetaData Data - (url: ${variables.url})`
|
||||
`Failed to validate My Page MetaData Data - (uid: ${variables.uid})`
|
||||
)
|
||||
console.error(validatedMetaDataData.error)
|
||||
return null
|
||||
}
|
||||
|
||||
return getMetaData(validatedMetaDataData.data.all_account_page.items[0])
|
||||
return getMetaData(validatedMetaDataData.data.account_page)
|
||||
}
|
||||
|
||||
export const metaDataQueryRouter = router({
|
||||
get: contentstackBaseProcedure.query(async ({ ctx }) => {
|
||||
if (!ctx.uid) {
|
||||
return []
|
||||
}
|
||||
|
||||
get: contentstackExtendedProcedureUID.query(async ({ ctx }) => {
|
||||
const variables = {
|
||||
locale: ctx.lang,
|
||||
url: ctx.pathname,
|
||||
uid: ctx.uid,
|
||||
}
|
||||
|
||||
switch (ctx.contentType) {
|
||||
@@ -69,7 +65,7 @@ export const metaDataQueryRouter = router({
|
||||
case PageTypeEnum.loyaltyPage:
|
||||
return await getLoyaltyPageMetaData(variables)
|
||||
default:
|
||||
return []
|
||||
return null
|
||||
}
|
||||
}),
|
||||
})
|
||||
|
||||
@@ -2,15 +2,22 @@ import { Lang } from "@/constants/languages"
|
||||
import { request } from "@/lib/graphql/request"
|
||||
import { internalServerError, notFound } from "@/server/errors/trpc"
|
||||
|
||||
import { generateTag } from "@/utils/generateTag"
|
||||
|
||||
import { getMetaDataSchema, Page } from "./output"
|
||||
|
||||
export type Variables = {
|
||||
locale: Lang
|
||||
url: string
|
||||
uid: string
|
||||
}
|
||||
|
||||
export async function getResponse<T>(query: string, variables: Variables) {
|
||||
const response = await request<T>(query, variables)
|
||||
const response = await request<T>(query, variables, {
|
||||
cache: "force-cache",
|
||||
next: {
|
||||
tags: [generateTag(variables.locale, variables.uid)],
|
||||
},
|
||||
})
|
||||
if (!response.data) {
|
||||
throw notFound(response)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user