Skip to content
This repository was archived by the owner on Feb 27, 2024. It is now read-only.

Commit 5d8c49a

Browse files
committed
Retrieve block data in post getter
1 parent df182d4 commit 5d8c49a

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

api/wordpress/_global/getPostTypeById.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import queryPostById from '../posts/queryPostById'
22
import {initializeApollo} from '../connector'
33
import queryPageById from '../pages/queryPageById'
44
import {isHierarchicalPostType} from './postTypes'
5+
import formatBlockData from '@/functions/formatBlockData'
56

67
/**
78
* Retrieve single post by specified identifier.
@@ -43,6 +44,20 @@ export default async function getPostTypeById(postType, id, idType = 'SLUG') {
4344
const post = await apolloClient
4445
.query({query, variables: {id, idType}})
4546
.then((post) => post?.data?.[postType] ?? null)
47+
.then(async (post) => {
48+
// Handle blocks.
49+
if (!post || !post?.blocksJSON) {
50+
return post
51+
}
52+
53+
const newPost = {...post}
54+
55+
newPost.blocks = await formatBlockData(
56+
JSON.parse(newPost.blocksJSON) ?? []
57+
)
58+
59+
return newPost
60+
})
4661
.catch((error) => {
4762
return {
4863
isError: true,

0 commit comments

Comments
 (0)