쿼리 라이브러리Bricks 페이지의 텍스트 요소를 주입된 콘텐츠로 교체하기
Bricks 페이지의 텍스트 요소를 주입된 콘텐츠로 교체하기
이 쿼리는 변수를 통해 주입된 데이터로 Bricks 페이지의 text 요소를 교체합니다.
이 쿼리를 사용하려면 Bricks 확장 기능이 활성화되어 있어야 합니다.
이 쿼리에는 다음 변수가 필요합니다:
$customPostId: 업데이트할 Bricks 커스텀 포스트의 ID$descriptions:text요소를 교체할 문자열 배열
query InitializeGlobalVariables
@configureWarningsOnExportingDuplicateVariable(enabled: false)
{
emptyArray: _echo(value: [])
@export(as: "elementToUpdateIDs")
}
query ExportData($customPostId: ID!)
@depends(on: "InitializeGlobalVariables")
{
customPost(by:{ id: $customPostId }, status: any) {
id
title
bricksData(filterBy: { include: ["text"] })
@underEachArrayItem
@underJSONObjectProperty(by: { key: "id" })
@export(as: "elementToUpdateIDs")
}
}
query ProcessData($descriptions: [String!]!)
@depends(on: "ExportData")
{ # Make sure the number of descriptions is the same as the number of elements to update
numberOfDescriptions: _arrayLength(array: $elementToUpdateIDs)
descriptions: _arrayPad(array: $descriptions, length: $__numberOfDescriptions, value: "")
@export(as: "adaptedDescriptions")
}
query AdaptData
@depends(on: "ProcessData")
{
elementToUpdateIDs: _echo(value: $elementToUpdateIDs)
elementToUpdateTexts: _echo(value: $adaptedDescriptions)
elementToUpdateMergeInputElements: _echo(value: $elementToUpdateIDs)
@underEachArrayItem(
passIndexOnwardsAs: "index",
passValueOnwardsAs: "elementToUpdateID"
affectDirectivesUnderPos: [1, 2]
)
@applyField(
name: "_arrayItem",
arguments: {
array: $adaptedDescriptions,
position: $index
},
passOnwardsAs: "elementToUpdateText"
)
@applyField(
name: "_echo",
arguments: {
value: {
id: $elementToUpdateID,
settings: {
text: $elementToUpdateText
}
}
}
setResultInResponse: true
)
@export(as: "elementToUpdateMergeInputElements")
}
mutation UpdateData($customPostId: ID!)
@depends(on: "AdaptData")
{
bricksMergeCustomPostElementDataItem(input: {
customPostID: $customPostId
elements: $elementToUpdateMergeInputElements
}) {
status
errors {
__typename
...on ErrorPayload {
message
@passOnwards(as: "message")
@fail(
message: $message
condition: ALWAYS
)
}
}
customPost {
__typename
...on CustomPost {
id
bricksData
}
}
}
}