Query 库复制 Bricks 文章
复制 Bricks 文章
此 query 可复制 Bricks 自定义文章(包括标题、内容、摘要、作者、特色图片和元数据),并为复制后的自定义文章重新生成 Bricks 元素 ID。
使用此 query 需要启用 Bricks 扩展。
此 query 需要以下变量:
customPostId:要复制的 Bricks 自定义文章的 ID。
query InitializeDynamicVariables
@configureWarningsOnExportingDuplicateVariable(enabled: false)
{
authorID: _echo(value: null)
@export(as: "authorID")
@remove
featuredImageID: _echo(value: null)
@export(as: "featuredImageID")
@remove
meta: _echo(value: {})
@export(as: "meta")
@remove
bricksIsEnabledForCustomPostType: _echo(value: false)
@export(as: "bricksIsEnabledForCustomPostType")
@remove
}
query GetBricksCustomPostAndExportData($customPostId: ID!)
@depends(on: "InitializeDynamicVariables")
{
customPost(by: { id: $customPostId }, status: any) {
bricksIsEnabledForCustomPostType
@export(as: "bricksIsEnabledForCustomPostType")
# Fields not to be duplicated
id
slug
date
status
# Fields to be duplicated
author {
id @export(as: "authorID")
}
customPostType @export(as: "customPostType")
rawContent @export(as: "rawContent")
rawExcerpt @export(as: "excerpt")
featuredImage {
id @export(as: "featuredImageID")
}
rawTitle @export(as: "title")
metaKeys(filter: { exclude: ["_thumbnail_id", "_edit_last"] })
meta(keys: $__metaKeys)
@export(as: "meta")
}
}
mutation DuplicateBricksCustomPost
@depends(on: "GetBricksCustomPostAndExportData")
@include(if: $bricksIsEnabledForCustomPostType)
{
createCustomPost(input: {
status: draft,
customPostType: $customPostType,
authorBy: {
id: $authorID
},
contentAs: {
html: $rawContent
},
excerpt: $excerpt
featuredImageBy: {
id: $featuredImageID
},
title: $title,
meta: $meta
}) {
status
errors {
__typename
...on ErrorPayload {
message
}
}
customPost {
# Fields not to be duplicated
id @export(as: "newCustomPostId")
slug
date
status
# Fields to be duplicated
customPostType
author {
id
}
rawContent
excerpt
featuredImage {
id
}
title
metaKeys(filter: { exclude: ["_thumbnail_id", "_edit_last"] })
meta(keys: $__metaKeys)
}
}
}
mutation RegenerateDuplicatedCustomPostBricksData
@depends(on: "DuplicateBricksCustomPost")
@include(if: $bricksIsEnabledForCustomPostType)
{
bricksRegenerateCustomPostElementIDSet(input: {
customPostID: $newCustomPostId
}) {
status
errors {
__typename
...on ErrorPayload {
message
}
}
}
}Next