쿼리 라이브러리게시물에 필수 댓글 블록 추가하기
게시물에 필수 댓글 블록 추가하기
이 쿼리는 변수 $postId로 지정된 게시물에 블록 wp:comments가 추가되어 있는지 확인합니다. 블록이 없을 경우 게시물 하단에 추가합니다.
이 쿼리를 실행하려면 엔드포인트에서 중첩 Mutation이 활성화되어 있어야 합니다.
query CheckIfCommentsBlockExists($postId: ID!) {
posts(
filter: {
ids: [$postId]
status: any
search: "\"<!-- /wp:comments -->\""
}
) {
id
...CommentBlocks
}
blockExists: _notEmpty(value: $__posts)
@export(as: "blockExists")
}
mutation InsertCommentsBlockIfMissingInPost($postId: ID!)
@depends(on: "CheckIfCommentsBlockExists")
@skip(if: $blockExists)
{
post(by: { id: $postId }, status: any) {
id
rawContent
adaptedRawContent: _strAppend(
after: $__rawContent
append: """
<!-- wp:comments -->
<div class="wp-block-comments"><!-- wp:comments-title /-->
<!-- wp:comment-template -->
<!-- wp:columns -->
<div class="wp-block-columns"><!-- wp:column {"width":"40px"} -->
<div class="wp-block-column" style="flex-basis:40px"><!-- wp:avatar {"size":40,"style":{"border":{"radius":"20px"}}} /--></div>
<!-- /wp:column -->
<!-- wp:column -->
<div class="wp-block-column"><!-- wp:comment-author-name {"fontSize":"small"} /-->
<!-- wp:group {"style":{"spacing":{"margin":{"top":"0px","bottom":"0px"}}},"layout":{"type":"flex"}} -->
<div class="wp-block-group" style="margin-top:0px;margin-bottom:0px"><!-- wp:comment-date {"fontSize":"small"} /-->
<!-- wp:comment-edit-link {"fontSize":"small"} /--></div>
<!-- /wp:group -->
<!-- wp:comment-content /-->
<!-- wp:comment-reply-link {"fontSize":"small"} /--></div>
<!-- /wp:column --></div>
<!-- /wp:columns -->
<!-- /wp:comment-template -->
<!-- wp:comments-pagination -->
<!-- wp:comments-pagination-previous /-->
<!-- wp:comments-pagination-numbers /-->
<!-- wp:comments-pagination-next /-->
<!-- /wp:comments-pagination -->
<!-- wp:post-comments-form /--></div>
<!-- /wp:comments -->
"""
)
update(input: {
contentAs: { html: $__adaptedRawContent },
}) {
status
errors {
__typename
...on ErrorPayload {
message
}
}
post {
id
rawContent
...CommentBlocks
}
}
}
}
fragment CommentBlocks on CustomPost {
blocks(filterBy: { include: ["core/comments"] }) {
... on Block {
name
attributes
}
}
}Prev
Next