fix(SW-194): split CS request of blocks into two
This commit is contained in:
@@ -37,7 +37,7 @@ query GetContentPage($locale: String!, $uid: String!) {
|
||||
}
|
||||
}
|
||||
|
||||
query GetContentPageBlocks($locale: String!, $uid: String!) {
|
||||
query GetContentPageBlocksBatch1($locale: String!, $uid: String!) {
|
||||
content_page(uid: $uid, locale: $locale) {
|
||||
blocks {
|
||||
__typename
|
||||
@@ -45,6 +45,14 @@ query GetContentPageBlocks($locale: String!, $uid: String!) {
|
||||
...CardsGrid_ContentPage
|
||||
...Content_ContentPage
|
||||
...DynamicContent_ContentPage
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
query GetContentPageBlocksBatch2($locale: String!, $uid: String!) {
|
||||
content_page(uid: $uid, locale: $locale) {
|
||||
blocks {
|
||||
__typename
|
||||
...Shortcuts_ContentPage
|
||||
...Table_ContentPage
|
||||
...TextCols_ContentPage
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import { Lang } from "@/constants/languages"
|
||||
import {
|
||||
GetContentPage,
|
||||
GetContentPageBlocks,
|
||||
GetContentPageBlocksBatch1,
|
||||
GetContentPageBlocksBatch2,
|
||||
} from "@/lib/graphql/Query/ContentPage/ContentPage.graphql"
|
||||
import { request } from "@/lib/graphql/request"
|
||||
import { contentstackExtendedProcedureUID, router } from "@/server/trpc"
|
||||
@@ -18,10 +19,7 @@ import {
|
||||
TrackingChannelEnum,
|
||||
type TrackingSDKPageData,
|
||||
} from "@/types/components/tracking"
|
||||
import type {
|
||||
GetContentPageSchema,
|
||||
GetContentPageSchemaBlocks,
|
||||
} from "@/types/trpc/routers/contentstack/contentPage"
|
||||
import type { GetContentPageSchema } from "@/types/trpc/routers/contentstack/contentPage"
|
||||
|
||||
export const contentPageQueryRouter = router({
|
||||
get: contentstackExtendedProcedureUID.query(async ({ ctx }) => {
|
||||
@@ -48,7 +46,7 @@ export const contentPageQueryRouter = router({
|
||||
})
|
||||
)
|
||||
|
||||
const [mainResponse, blocksResponse] = await Promise.all([
|
||||
const [mainResponse, blocksResponse1, blocksResponse2] = await Promise.all([
|
||||
request<GetContentPageSchema>(
|
||||
GetContentPage,
|
||||
{ locale: lang, uid },
|
||||
@@ -60,7 +58,17 @@ export const contentPageQueryRouter = router({
|
||||
}
|
||||
),
|
||||
request<GetContentPageSchema>(
|
||||
GetContentPageBlocks,
|
||||
GetContentPageBlocksBatch1,
|
||||
{ locale: lang, uid },
|
||||
{
|
||||
cache: "force-cache",
|
||||
next: {
|
||||
tags,
|
||||
},
|
||||
}
|
||||
),
|
||||
request<GetContentPageSchema>(
|
||||
GetContentPageBlocksBatch2,
|
||||
{ locale: lang, uid },
|
||||
{
|
||||
cache: "force-cache",
|
||||
@@ -75,7 +83,12 @@ export const contentPageQueryRouter = router({
|
||||
...mainResponse.data,
|
||||
content_page: {
|
||||
...mainResponse.data.content_page,
|
||||
blocks: blocksResponse.data.content_page.blocks,
|
||||
blocks: [
|
||||
blocksResponse1.data.content_page.blocks,
|
||||
blocksResponse2.data.content_page.blocks,
|
||||
]
|
||||
.flat(2)
|
||||
.filter((obj) => !(obj && Object.keys(obj).length < 2)), // Remove empty objects and objects with only typename
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user