fix(SW-194): split CS request of blocks into two

This commit is contained in:
Matilda Landström
2024-10-15 17:01:34 +02:00
parent 47aa63cd9f
commit 510311a0dc
2 changed files with 30 additions and 9 deletions

View File

@@ -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) { content_page(uid: $uid, locale: $locale) {
blocks { blocks {
__typename __typename
@@ -45,6 +45,14 @@ query GetContentPageBlocks($locale: String!, $uid: String!) {
...CardsGrid_ContentPage ...CardsGrid_ContentPage
...Content_ContentPage ...Content_ContentPage
...DynamicContent_ContentPage ...DynamicContent_ContentPage
}
}
}
query GetContentPageBlocksBatch2($locale: String!, $uid: String!) {
content_page(uid: $uid, locale: $locale) {
blocks {
__typename
...Shortcuts_ContentPage ...Shortcuts_ContentPage
...Table_ContentPage ...Table_ContentPage
...TextCols_ContentPage ...TextCols_ContentPage

View File

@@ -1,7 +1,8 @@
import { Lang } from "@/constants/languages" import { Lang } from "@/constants/languages"
import { import {
GetContentPage, GetContentPage,
GetContentPageBlocks, GetContentPageBlocksBatch1,
GetContentPageBlocksBatch2,
} from "@/lib/graphql/Query/ContentPage/ContentPage.graphql" } from "@/lib/graphql/Query/ContentPage/ContentPage.graphql"
import { request } from "@/lib/graphql/request" import { request } from "@/lib/graphql/request"
import { contentstackExtendedProcedureUID, router } from "@/server/trpc" import { contentstackExtendedProcedureUID, router } from "@/server/trpc"
@@ -18,10 +19,7 @@ import {
TrackingChannelEnum, TrackingChannelEnum,
type TrackingSDKPageData, type TrackingSDKPageData,
} from "@/types/components/tracking" } from "@/types/components/tracking"
import type { import type { GetContentPageSchema } from "@/types/trpc/routers/contentstack/contentPage"
GetContentPageSchema,
GetContentPageSchemaBlocks,
} from "@/types/trpc/routers/contentstack/contentPage"
export const contentPageQueryRouter = router({ export const contentPageQueryRouter = router({
get: contentstackExtendedProcedureUID.query(async ({ ctx }) => { 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>( request<GetContentPageSchema>(
GetContentPage, GetContentPage,
{ locale: lang, uid }, { locale: lang, uid },
@@ -60,7 +58,17 @@ export const contentPageQueryRouter = router({
} }
), ),
request<GetContentPageSchema>( request<GetContentPageSchema>(
GetContentPageBlocks, GetContentPageBlocksBatch1,
{ locale: lang, uid },
{
cache: "force-cache",
next: {
tags,
},
}
),
request<GetContentPageSchema>(
GetContentPageBlocksBatch2,
{ locale: lang, uid }, { locale: lang, uid },
{ {
cache: "force-cache", cache: "force-cache",
@@ -75,7 +83,12 @@ export const contentPageQueryRouter = router({
...mainResponse.data, ...mainResponse.data,
content_page: { content_page: {
...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
}, },
} }