Thư viện QueriesNhân bản một trang
Nhân bản một trang
Query này nhân bản một trang, bao gồm tiêu đề, nội dung, trích dẫn, tác giả, ảnh đại diện và siêu dữ liệu.
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
}
query GetPageAndExportData($pageId: ID!)
@depends(on: "InitializeDynamicVariables")
{
page(by: { id: $pageId }, status: any) {
# Fields not to be duplicated
id
slug
date
status
# Fields to be duplicated
author {
id @export(as: "authorID")
}
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 DuplicatePage
@depends(on: "GetPageAndExportData")
{
createPage(input: {
status: draft,
authorBy: {
id: $authorID
},
contentAs: {
html: $rawContent
},
excerpt: $excerpt
featuredImageBy: {
id: $featuredImageID
},
title: $title,
meta: $meta
}) {
status
errors {
__typename
...on ErrorPayload {
message
}
}
page {
# Fields not to be duplicated
id
slug
date
status
# Fields to be duplicated
author {
id
}
rawContent
excerpt
featuredImage {
id
}
title
metaKeys(filter: { exclude: ["_thumbnail_id", "_edit_last"] })
meta(keys: $__metaKeys)
}
}
}