Queries KütüphanesiBricks gönderisine CSV verisi enjekte et
Bricks gönderisine CSV verisi enjekte et
Bu query, CSV verilerini ayrıştırır ve bir Bricks sayfasındaki text öğelerine enjekte eder.
Bu query'nin çalışması için Bricks uzantısının etkinleştirilmiş olması gerekir.
Query aşağıdaki değişkenleri gerektirir:
$customPostId: Güncellenecek Bricks özel gönderisinin kimliği$csvFileURL: Ayrıştırılacak CSV dosyasının URL'si
query InitializeGlobalVariables
@configureWarningsOnExportingDuplicateVariable(enabled: false)
{
emptyArray: _echo(value: [])
@export(as: "elementToUpdateIDs")
emptyNumber: _echo(value: 0)
@export(as: "numberCsvEntries")
}
query GetCSVData(
$url: URL!
$headingElementColumn: String! = "Title"
$textElementColumn: String! = "Description"
)
@depends(on: "InitializeGlobalVariables")
{
_sendHTTPRequest(input: {
url: $url,
method: GET
}) {
body
csv: _strParseCSV(
string: $__body
)
@underEachArrayItem(
passValueOnwardsAs: "csvPostEntry"
affectDirectivesUnderPos: [1, 3]
)
@underJSONObjectProperty(by: { key: $headingElementColumn })
@export(as: "csvHeadings")
@underJSONObjectProperty(by: { key: $textElementColumn })
@export(as: "csvTexts")
numberCsvEntries: _arrayLength(array: $__csv)
@export(as: "numberCsvEntries")
}
}
query ExportData($customPostId: ID!)
@depends(on: "GetCSVData")
{
customPost(by:{ id: $customPostId }, status: any) {
id
title
bricksDataTextElements: bricksData(filterBy: { include: ["text"] })
@arraySplice(offset: $numberCsvEntries)
@underEachArrayItem(
passIndexOnwardsAs: "index",
passValueOnwardsAs: "elementJSON"
affectDirectivesUnderPos: [1, 2, 3]
)
@applyField(
name: "_objectProperty",
arguments: {
object: $elementJSON,
by: { key: "id" }
},
passOnwardsAs: "elementID"
)
@applyField(
name: "_arrayItem",
arguments: {
array: $csvTexts,
position: $index
},
passOnwardsAs: "csvText"
)
@applyField(
name: "_echo",
arguments: {
value: {
id: $elementID,
settings: {
text: $csvText
}
}
}
setResultInResponse: true
)
@export(as: "textMergeInputElements")
bricksDataHeadingElements: bricksData(filterBy: { include: ["heading"] })
@arraySplice(offset: $numberCsvEntries)
@underEachArrayItem(
passIndexOnwardsAs: "index",
passValueOnwardsAs: "elementJSON"
affectDirectivesUnderPos: [1, 2, 3]
)
@applyField(
name: "_objectProperty",
arguments: {
object: $elementJSON,
by: { key: "id" }
},
passOnwardsAs: "elementID"
)
@applyField(
name: "_arrayItem",
arguments: {
array: $csvHeadings,
position: $index
},
passOnwardsAs: "csvHeading"
)
@applyField(
name: "_echo",
arguments: {
value: {
id: $elementID,
settings: {
text: $csvHeading
}
}
}
setResultInResponse: true
)
@export(as: "headingMergeInputElements")
}
}
query AdaptData
@depends(on: "ExportData")
{
allMergeInputElements: _arrayMerge(
arrays: [$textMergeInputElements, $headingMergeInputElements]
)
@export(as: "allMergeInputElements")
}
mutation UpdateData($customPostId: ID!)
@depends(on: "AdaptData")
{
bricksMergeCustomPostElementDataItem(input: {
customPostID: $customPostId
elements: $allMergeInputElements
}) {
status
errors {
__typename
...on ErrorPayload {
message
@passOnwards(as: "message")
@fail(
message: $message
condition: ALWAYS
)
}
}
customPost {
__typename
...on CustomPost {
id
bricksData
}
}
}
}