Bricks 페이지를 스테이징에서 프로덕션으로 Sync(이미지 포함)
스테이징 WordPress 사이트에서 Bricks 페이지 또는 템플릿을 가져와 프로덕션 WordPress 사이트에 복제하며, 이미지도 함께 동기화합니다

Gato GraphQL과 Bricks 확장 기능을 함께 사용하면 스테이징 WordPress 사이트에서 Bricks 페이지 또는 템플릿을 내보내고 프로덕션 WordPress 사이트에 복제할 수 있으며, 이미지도 함께 동기화됩니다.
Gato GraphQL 플러그인 + Power Extensions + Bricks 확장 기능은 스테이징 사이트와 프로덕션 사이트 모두에 설치되어 있어야 합니다.
스테이징 사이트와 프로덕션 사이트 간의 공통 식별자는 슬러그입니다. 슬러그가 프로덕션 사이트에 없으면 쿼리가 새 Bricks 페이지를 생성합니다. 슬러그가 발견되면 기존 Bricks 페이지를 업데이트합니다.
쿼리는 스테이징 사이트의 Bricks 페이지에 포함된 누락된 미디어 항목을 모두 가져옵니다:
- 페이지의 대표 이미지
- 모든 Bricks 요소의 배경 이미지
- 다음 유형의 모든 Bricks 요소 이미지:
imageimage-gallerylogosvg
각 이미지에 대해 쿼리는 프로덕션 사이트에 동일한 슬러그를 가진 이미지가 있는지 확인합니다(슬러그는 사이트 간 미디어 항목의 공통 식별자입니다). 있으면 프로덕션 사이트의 이미지 ID를 사용합니다. 없으면 프로덕션 사이트로 이미지를 가져와 해당 ID를 Bricks 요소에 할당합니다.
스테이징 사이트는 URL을 통해 이미지를 가져올 수 있도록 프로덕션 사이트에서 접근 가능해야 합니다. 스테이징 도메인이 안전하지 않은 것으로 간주되는 경우(예: .local 도메인), 프로덕션 사이트에서 안전하지 않은 URL을 허용해야 합니다.
두 사이트 모두 해당 커스텀 게시물 유형에 대한 접근을 허용해야 합니다(bricks_template, page, 또는 그 외 유형).
다음 변수를 제공해야 합니다:
postSlug: 전송할 Bricks 페이지 또는 템플릿(또는 다른 커스텀 게시물 유형)의 슬러그prodSiteGraphQLEndpointURL: 프로덕션 WordPress 사이트의 GraphQL 엔드포인트 URLupdateMediaItems: 프로덕션 사이트에 이미 존재하는 미디어 항목을 업데이트할지 여부. 기본값은true입니다.username: 프로덕션 사이트 인증에 사용할 사용자 이름appPassword: 프로덕션 사이트 인증에 사용할 애플리케이션 비밀번호
GraphQL 쿼리는 다음과 같습니다:
query InitializeVariables
@configureWarningsOnExportingDuplicateVariable(enabled: false)
{
emptyArray: _echo(value: [])
@export(as: "imageSlugs")
@export(as: "bricksAnyElementBackgroundImageIDs")
@export(as: "bricksImageElementImageIDs")
@export(as: "bricksSvgElementFileIDs")
@export(as: "bricksLogoElementLogoIDs")
@export(as: "bricksLogoElementLogoInverseIDs")
@export(as: "bricksImageGalleryElementListIDItems")
@remove
emptyID: _echo(value: null)
@export(as: "featuredImageID")
@remove
emptyBool: _echo(value: false)
@export(as: "bricksIsEnabledForCustomPostType")
@remove
}
query GetPostData(
$postTypes: [String!]! = ["bricks_template", "page"]
$postSlug: String!
)
@depends(on: "InitializeVariables")
{
customPost(by: { slug: $postSlug }, customPostTypes: $postTypes, status: any)
@fail(
message: "There is no Bricks page in the staging site with the provided slug"
data: {
slug: $postSlug
}
)
{
rawTitle
@export(as: "postTitle")
rawContent
@export(as: "postContent")
rawExcerpt
@export(as: "postExcerpt")
rawStatus
@export(as: "postStatus")
date
@export(as: "postDate")
gmtDate: date(gmt: true)
@export(as: "postGmtDate")
customPostType
@export(as: "postType")
featuredImage {
id @export(as: "featuredImageID")
}
metaKeys(filter: { exclude: ["_edit_last", "_edit_lock", "_pingme", "_encloseme", "_trackbackme", "enclosure", "_thumbnail_id", "_wp_trash_meta_status", "_wp_trash_meta_time", "_wp_desired_post_slug", "_wp_old_slug", "_wp_old_date"] })
meta(keys: $__metaKeys)
@export(as: "postMeta")
bricksIsEnabledForCustomPostType
@export(as: "bricksIsEnabledForCustomPostType")
bricksAnyElementBackgroundImageElementsData: bricksData
@underEachArrayItem
@underJSONObjectProperty(
by: { path: "settings._background.image.id" }
failIfNonExistingKeyOrPath: false
)
@export(as: "bricksAnyElementBackgroundImageIDs")
bricksImageElementsData: bricksData( filterBy:{ include: ["image"] } )
@underEachArrayItem
@underJSONObjectProperty(
by: { path: "settings.image.id" }
# External images have no ID
failIfNonExistingKeyOrPath: false
)
@export(as: "bricksImageElementImageIDs")
bricksSvgElementsData: bricksData( filterBy:{ include: ["svg"] } )
@underEachArrayItem
@underJSONObjectProperty(
by: { path: "settings.file.id" }
failIfNonExistingKeyOrPath: false
)
@export(as: "bricksSvgElementFileIDs")
bricksLogoElementsData: bricksData( filterBy:{ include: ["logo"] } )
@underEachArrayItem(
affectDirectivesUnderPos: [1, 3]
)
@underJSONObjectProperty(
by: { path: "settings.logo.id" }
failIfNonExistingKeyOrPath: false
)
@export(as: "bricksLogoElementLogoIDs")
@underJSONObjectProperty(
by: { path: "settings.logoInverse.id" }
failIfNonExistingKeyOrPath: false
)
@export(as: "bricksLogoElementLogoInverseIDs")
bricksImageGalleryElementsData: bricksData( filterBy:{ include: ["image-gallery"] } )
@underEachArrayItem
@underJSONObjectProperty(
by: { path: "settings.items.images" }
failIfNonExistingKeyOrPath: false
)
@underEachArrayItem
@underJSONObjectProperty(
by: { key: "id" }
failIfNonExistingKeyOrPath: false
)
@export(as: "bricksImageGalleryElementListIDItems")
}
isMissingPostInStaging: _isNull(value: $__customPost)
@export(as: "isMissingPostInStaging")
}
query MaybeFailIfPostIsNotEnabledForBricks
@depends(on: "GetPostData")
@skip(if: $isMissingPostInStaging)
@skip(if: $bricksIsEnabledForCustomPostType)
{
_fail(message: "Bricks is not enabled for the custom post type")
}
query FetchAndExportImageData
@depends(on: "MaybeFailIfPostIsNotEnabledForBricks")
@include(if: $bricksIsEnabledForCustomPostType)
{
# External images have no ID, and the featured image may be `null`
mediaItemsIDsToExport: _arrayMerge(
arrays: [
[$featuredImageID],
$bricksAnyElementBackgroundImageIDs,
$bricksImageElementImageIDs,
$bricksSvgElementFileIDs,
$bricksLogoElementLogoIDs,
$bricksLogoElementLogoInverseIDs,
$bricksImageGalleryElementListIDItems,
]
)
filteredMediaItemsIDsToExport: _arrayFilter(array: $__mediaItemsIDsToExport)
mediaItems(filter: { ids: $__filteredMediaItemsIDsToExport, mimeTypes: "*" }, pagination: { limit: -1 }) {
id
src(size: "full")
slug
title
caption
altText
description
date
gmtDate: date(gmt: true)
mimeType
@export(
as: "imageData"
type: LIST
affectAdditionalFieldsUnderPos: [1, 2, 3, 4, 5, 6, 7, 8, 9]
)
}
}
query ExportBricksPostToProductionSite(
$postSlug: String!
$prodSiteGraphQLEndpointURL: String!
$username: String!
$appPassword: String!
$updateMediaItems: Boolean! = true
)
@depends(on: "FetchAndExportImageData")
@include(if: $bricksIsEnabledForCustomPostType)
{
loginCredentials: _sprintf(
string: "%s:%s",
values: [$username, $appPassword]
)
@remove
base64EncodedLoginCredentials: _strBase64Encode(
string: $__loginCredentials
)
@remove
loginCredentialsHeaderValue: _sprintf(
string: "Basic %s",
values: [$__base64EncodedLoginCredentials]
)
@remove
requestAgainstProductionSite: _sendGraphQLHTTPRequest(
input: {
endpoint: $prodSiteGraphQLEndpointURL,
query: """
query InitializeVariables
@configureWarningsOnExportingDuplicateVariable(enabled: false)
{
emptyArray: _echo(value: [])
@export(as: "existingLocalImagesWithSlugs")
@export(as: "localMediaItemData")
@export(as: "mergeBricksAnyElementBackgroundImageEntries")
@export(as: "mergeBricksImageElementImageEntries")
@export(as: "mergeBricksSvgElementFileEntries")
@export(as: "mergeBricksLogoElementLogoEntries")
@export(as: "mergeBricksLogoElementLogoInverseEntries")
@export(as: "mergeBricksImageGalleryElementImageEntries")
@export(as: "computeBricksImageGalleryElementListIDs")
@export(as: "computeBricksImageGalleryElementListElementProps")
@export(as: "computeBricksImageGalleryElementListImageEntries")
@remove
emptyID: _echo(value: null)
@export(as: "postId")
@export(as: "localFeaturedImageID")
@remove
}
query ExportData(
$featuredImageID: ID!
)
@depends(on: "InitializeVariables")
{
originalImageSizeNames: imageSizeNames
@remove
imageSizeNames: _arrayAddItem(array: $__originalImageSizeNames, value: "full")
@export(as: "imageSizeNames")
hasFeaturedImageID: _notNull(value: $featuredImageID)
@export(as: "hasFeaturedImageID")
}
############################################################################
# Calculate what images are already in the production site
############################################################################
query ProcessImageDataBySlugs(
$imageData: [JSONObject!]!
)
@depends(on: "ExportData")
{
imageDataByID: _arrayOfJSONObjectsExtractPropertyAndConvertToObject(
array: $imageData,
key: "id",
)
@export(as: "imageDataByID")
imageDataBySlug: _arrayOfJSONObjectsExtractPropertyAndConvertToObject(
array: $imageData,
key: "slug",
)
@export(as: "imageDataBySlug")
imageSlugs: _objectProperties(object: $__imageDataBySlug)
@export(as: "imageSlugs")
}
query RetrieveExistingLocalImageData
@depends(on: "ProcessImageDataBySlugs")
{
existingLocalImagesWithSlugs: mediaItems(filter: { slugs: $imageSlugs, mimeTypes: "*" }, pagination: { limit: -1 }) {
id
slug
@export(
as: "existingLocalImagesWithSlugs"
type: LIST
affectAdditionalFieldsUnderPos: [1]
)
}
}
query ComputeLocalImagesData
@depends(on: "RetrieveExistingLocalImageData")
{
existingLocalImagesBySlug: _arrayOfJSONObjectsExtractPropertyAndConvertToObject(
array: $existingLocalImagesWithSlugs,
key: "slug",
)
existingLocalImageSlugs: _objectProperties(object: $__existingLocalImagesBySlug)
existingLocalImageDataBySlug: _objectIntersectKeyWithArrays(object: $imageDataBySlug, arrays: [$__existingLocalImageSlugs])
@remove
existingLocalImageData: _objectValues(object: $__existingLocalImageDataBySlug)
@export(as: "existingLocalImageData")
nonExistingLocalImageSlugs: _arrayDiff(arrays: [$imageSlugs, $__existingLocalImageSlugs])
nonExistingLocalImageDataBySlug: _objectIntersectKeyWithArrays(object: $imageDataBySlug, arrays: [$__nonExistingLocalImageSlugs])
@remove
nonExistingLocalImageData: _objectValues(object: $__nonExistingLocalImageDataBySlug)
@export(as: "nonExistingLocalImageData")
}
############################################################################
# Prepare variables to convert external images to local images
############################################################################
query RetrieveImageData
@depends(on: "ComputeLocalImagesData")
{
localMediaItemData: mediaItems(filter: { slugs: $imageSlugs, mimeTypes: "*" }, pagination: { limit: -1 }) {
id
slug
src(size: "full")
srcs(sizes: $imageSizeNames)
full: src(size: "full")
@export(
as: "localMediaItemData"
type: LIST
affectAdditionalFieldsUnderPos: [1, 2, 3, 4]
)
}
}
query ComputeImages
@depends(on: "RetrieveImageData")
{
localMediaItemDataBySlug: _arrayOfJSONObjectsExtractPropertyAndConvertToObject(
array: $localMediaItemData,
key: "slug",
)
@export(as: "localMediaItemDataBySlug")
}
############################################################################
# Import images from the staging site
############################################################################
query GenerateCreateImageMutationInputs
@depends(on: "ComputeImages")
{
createMediaItemsInputs: _echo(value: $nonExistingLocalImageData)
@underEachArrayItem(
passValueOnwardsAs: "mediaItemData"
affectDirectivesUnderPos: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
)
@applyField(
name: "_objectProperty"
arguments: {
object: $mediaItemData,
by: { key: "src" }
}
passOnwardsAs: "src"
)
@applyField(
name: "_objectProperty"
arguments: {
object: $mediaItemData,
by: { key: "slug" }
}
passOnwardsAs: "slug"
)
@applyField(
name: "_objectProperty"
arguments: {
object: $mediaItemData,
by: { key: "title" }
}
passOnwardsAs: "title"
)
@applyField(
name: "_objectProperty"
arguments: {
object: $mediaItemData,
by: { key: "caption" }
}
passOnwardsAs: "caption"
)
@applyField(
name: "_objectProperty"
arguments: {
object: $mediaItemData,
by: { key: "altText" }
}
passOnwardsAs: "altText"
)
@applyField(
name: "_objectProperty"
arguments: {
object: $mediaItemData,
by: { key: "description" }
}
passOnwardsAs: "description"
)
@applyField(
name: "_objectProperty"
arguments: {
object: $mediaItemData,
by: { key: "gmtDate" }
}
passOnwardsAs: "gmtDate"
)
@applyField(
name: "_objectProperty"
arguments: {
object: $mediaItemData,
by: { key: "date" }
}
passOnwardsAs: "date"
)
@applyField(
name: "_objectProperty"
arguments: {
object: $mediaItemData,
by: { key: "mimeType" }
}
passOnwardsAs: "mimeType"
)
@applyField(
name: "_echo"
arguments: {
value: {
from: {
url: {
source: $src
}
},
slug: $slug,
title: $title,
caption: $caption,
altText: $altText,
description: $description,
date: $date,
gmtDate: $gmtDate,
mimeType: $mimeType,
}
}
setResultInResponse: true
)
@export(as: "createMediaItemsInputs")
}
mutation ImportImages
@depends(on: "GenerateCreateImageMutationInputs")
{
createMediaItems(inputs: $createMediaItemsInputs) {
mediaItemID
status
errors {
__typename
...on ErrorPayload {
message
}
}
mediaItem {
...MediaItemData
}
}
}
############################################################################
# Update the already-existing media items in the production site
############################################################################
query GenerateUpdateImageMutationInputs(
$updateMediaItems: Boolean! = true
)
@depends(on: "ImportImages")
@include(if: $updateMediaItems)
{
updateMediaItemsInputs: _echo(value: $existingLocalImageData)
@underEachArrayItem(
passValueOnwardsAs: "mediaItemData"
affectDirectivesUnderPos: [1, 2, 3, 4, 5, 6, 7, 8]
)
@applyField(
name: "_objectProperty"
arguments: {
object: $mediaItemData,
by: { key: "slug" }
}
passOnwardsAs: "commonSlug"
)
@applyField(
name: "_objectProperty"
arguments: {
object: $localMediaItemDataBySlug,
by: { key: $commonSlug }
}
passOnwardsAs: "localImageData"
)
@applyField(
name: "_objectProperty"
arguments: {
object: $localImageData,
by: { key: "id" }
}
passOnwardsAs: "id"
)
@applyField(
name: "_objectProperty"
arguments: {
object: $mediaItemData,
by: { key: "title" }
}
passOnwardsAs: "title"
)
@applyField(
name: "_objectProperty"
arguments: {
object: $mediaItemData,
by: { key: "caption" }
}
passOnwardsAs: "caption"
)
@applyField(
name: "_objectProperty"
arguments: {
object: $mediaItemData,
by: { key: "altText" }
}
passOnwardsAs: "altText"
)
@applyField(
name: "_objectProperty"
arguments: {
object: $mediaItemData,
by: { key: "description" }
}
passOnwardsAs: "description"
)
@applyField(
name: "_echo"
arguments: {
value: {
id: $id,
title: $title,
caption: $caption,
altText: $altText,
description: $description,
}
}
setResultInResponse: true
)
@export(as: "updateMediaItemsInputs")
}
mutation UpdateImages(
$updateMediaItems: Boolean! = true
)
@depends(on: "GenerateUpdateImageMutationInputs")
@include(if: $updateMediaItems)
{
updateMediaItems(inputs: $updateMediaItemsInputs) {
mediaItemID
status
errors {
__typename
...on ErrorPayload {
message
}
}
mediaItem {
...MediaItemData
}
}
}
fragment MediaItemData on Media {
altText
caption
mimeType
slug
src
title
}
############################################################################
# Adapt the featured image to use the local image
############################################################################
query AdaptFeaturedImageToLocalImage(
$featuredImageID: ID!
)
@depends(on: "UpdateImages")
@include(if: $hasFeaturedImageID)
{
featuredImageID: _echo(value: $featuredImageID)
@passOnwards(as: "externalFeaturedImageID")
@applyField(
name: "_objectProperty"
arguments: {
object: $imageDataByID,
by: { key: $externalFeaturedImageID }
}
passOnwardsAs: "externalImageData"
)
@applyField(
name: "_objectProperty"
arguments: {
object: $externalImageData,
by: { key: "slug" }
}
passOnwardsAs: "commonSlug"
)
@applyField(
name: "_objectProperty"
arguments: {
object: $localMediaItemDataBySlug,
by: { key: $commonSlug }
}
passOnwardsAs: "localImageData"
)
@applyField(
name: "_objectProperty"
arguments: {
object: $localImageData,
by: { key: "id" }
}
setResultInResponse: true
)
@export(as: "localFeaturedImageID")
}
############################################################################
# Create/update the Bricks post with the external data
############################################################################
query CheckIfCustomPostExists(
$postSlug: String!
$postType: String!
)
@depends(on: "AdaptFeaturedImageToLocalImage")
{
maybeCustomPost: customPost(by: { slug: $postSlug }, customPostTypes: [$postType], status: any)
{
id
}
customPostExists: _notNull(value: $__maybeCustomPost)
@export(as: "customPostExists")
}
mutation CreateOrUpdateCustomPost(
$postSlug: String!
$postTitle: String!
$postContent: String!
$postExcerpt: String!
$postStatus: CustomPostStatusEnum!
$postDate: DateTime!
$postGmtDate: DateTime!
$postType: String!
$postMeta: JSONObject!
)
@depends(on: "CheckIfCustomPostExists")
{
customPost(by: { slug: $postSlug }, customPostTypes: [$postType], status: any)
@include(if: $customPostExists)
{
id
@export(as: "postId")
update(input: {
title: $postTitle,
contentAs: { html: $postContent },
excerpt: $postExcerpt,
status: $postStatus,
date: $postDate,
gmtDate: $postGmtDate,
featuredImageBy: {
id: $localFeaturedImageID
},
meta: $postMeta
}) {
status
errors {
__typename
...on ErrorPayload {
message
}
}
...on GenericCustomPostUpdateMutationPayload {
customPost {
...CustomPostData
}
}
...on PostUpdateMutationPayload {
post {
...CustomPostData
}
}
...on PageUpdateMutationPayload {
page {
...CustomPostData
}
}
}
}
createCustomPost(input: {
title: $postTitle,
slug: $postSlug,
contentAs: { html: $postContent },
excerpt: $postExcerpt,
status: $postStatus,
date: $postDate,
gmtDate: $postGmtDate,
featuredImageBy: {
id: $localFeaturedImageID
},
customPostType: $postType,
meta: $postMeta
})
@skip(if: $customPostExists)
{
status
errors {
__typename
...on ErrorPayload {
message
}
}
customPostID
@export(as: "postId")
customPost {
...CustomPostData
}
}
}
fragment CustomPostData on CustomPost {
id
title
slug
content
excerpt
status
date
gmtDate: date(gmt: true)
metaKeys
meta(keys: $__metaKeys)
}
############################################################################
# Update the Bricks Image elements to use the local images
############################################################################
query ExportBricksImageData(
$postSlug: String!
$postType: String!
)
@depends(on: "CreateOrUpdateCustomPost")
{
updateBricksImageDataCustomPost: customPost(by: { slug: $postSlug }, customPostTypes: [$postType], status: any) {
id
bricksAnyElementBackgroundImageElementsData: bricksData
@underEachArrayItem(
affectDirectivesUnderPos: [1, 2, 3]
passValueOnwardsAs: "bricksElement"
)
@applyField(
name: "_objectProperty"
arguments: {
object: $bricksElement,
by: { path: "settings._background.image.id" }
failIfNonExistingKeyOrPath: false
}
passOnwardsAs: "bricksElementBackgroundImageID"
)
# External images have no ID
@applyField(
name: "_notNull"
arguments: {
value: $bricksElementBackgroundImageID
}
passOnwardsAs: "hasBricksAnyElementBackgroundImageID"
)
@if(
condition: $hasBricksAnyElementBackgroundImageID
affectDirectivesUnderPos: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
)
@applyField(
name: "_objectProperty"
arguments: {
object: $bricksElement,
by: { key: "id" }
}
passOnwardsAs: "elementID"
)
@applyField(
name: "_objectProperty"
arguments: {
object: $bricksElement,
by: { path: "settings._background.image.size" }
}
passOnwardsAs: "imageSize"
)
@applyField(
name: "_arraySearch",
arguments: {
array: $imageSizeNames
element: $imageSize
}
passOnwardsAs: "imageSizePosition"
)
# `$bricksElementBackgroundImageID` it contains the ID of the image from staging, find the ID for production and create a new merge mutation entry
@applyField(
name: "_objectProperty"
arguments: {
object: $imageDataByID,
by: { key: $bricksElementBackgroundImageID }
}
passOnwardsAs: "externalImageData"
)
@applyField(
name: "_objectProperty"
arguments: {
object: $externalImageData,
by: { key: "slug" }
}
passOnwardsAs: "commonSlug"
)
@applyField(
name: "_objectProperty"
arguments: {
object: $localMediaItemDataBySlug,
by: { key: $commonSlug }
}
passOnwardsAs: "localImageData"
)
@applyField(
name: "_objectProperty"
arguments: {
object: $localImageData,
by: { key: "id" }
}
passOnwardsAs: "localImageID"
)
@applyField(
name: "_objectProperty"
arguments: {
object: $localImageData,
by: { key: "srcs" }
}
passOnwardsAs: "localImageSrcs"
)
@applyField(
name: "_arrayItem"
arguments: {
array: $localImageSrcs,
position: $imageSizePosition
}
passOnwardsAs: "localImageSrc"
)
@applyField(
name: "_objectProperty"
arguments: {
object: $localImageData,
by: { key: "full" }
}
passOnwardsAs: "localImageFull"
)
@applyField(
name: "_echo"
arguments: {
value: {
id: $elementID,
settings: {
_background: {
image: {
id: $localImageID,
full: $localImageFull,
url: $localImageSrc
}
}
}
}
}
passOnwardsAs: "mergeBricksEntry"
)
@exportFrom(
scopedDynamicVariable: $mergeBricksEntry,
as: "mergeBricksAnyElementBackgroundImageEntries"
)
bricksImageElementsData: bricksData( filterBy: { include: ["image"] } )
@underEachArrayItem(
affectDirectivesUnderPos: [1, 2, 3]
passValueOnwardsAs: "bricksImageElement"
)
@applyField(
name: "_objectProperty"
arguments: {
object: $bricksImageElement,
by: { path: "settings.image.id" }
failIfNonExistingKeyOrPath: false
}
passOnwardsAs: "bricksImageElementImageID"
)
# External images have no ID
@applyField(
name: "_notNull"
arguments: {
value: $bricksImageElementImageID
}
passOnwardsAs: "hasBricksImageElementImageID"
)
@if(
condition: $hasBricksImageElementImageID
affectDirectivesUnderPos: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
)
@applyField(
name: "_objectProperty"
arguments: {
object: $bricksImageElement,
by: { key: "id" }
}
passOnwardsAs: "elementID"
)
@applyField(
name: "_objectProperty"
arguments: {
object: $bricksImageElement,
by: { path: "settings.image.size" }
}
passOnwardsAs: "imageSize"
)
@applyField(
name: "_arraySearch",
arguments: {
array: $imageSizeNames
element: $imageSize
}
passOnwardsAs: "imageSizePosition"
)
# `$bricksImageElementImageID` it contains the ID of the image from staging, find the ID for production and create a new merge mutation entry
@applyField(
name: "_objectProperty"
arguments: {
object: $imageDataByID,
by: { key: $bricksImageElementImageID }
}
passOnwardsAs: "externalImageData"
)
@applyField(
name: "_objectProperty"
arguments: {
object: $externalImageData,
by: { key: "slug" }
}
passOnwardsAs: "commonSlug"
)
@applyField(
name: "_objectProperty"
arguments: {
object: $localMediaItemDataBySlug,
by: { key: $commonSlug }
}
passOnwardsAs: "localImageData"
)
@applyField(
name: "_objectProperty"
arguments: {
object: $localImageData,
by: { key: "id" }
}
passOnwardsAs: "localImageID"
)
@applyField(
name: "_objectProperty"
arguments: {
object: $localImageData,
by: { key: "srcs" }
}
passOnwardsAs: "localImageSrcs"
)
@applyField(
name: "_arrayItem"
arguments: {
array: $localImageSrcs,
position: $imageSizePosition
}
passOnwardsAs: "localImageSrc"
)
@applyField(
name: "_objectProperty"
arguments: {
object: $localImageData,
by: { key: "full" }
}
passOnwardsAs: "localImageFull"
)
@applyField(
name: "_echo"
arguments: {
value: {
id: $elementID,
settings: {
image: {
id: $localImageID,
full: $localImageFull,
url: $localImageSrc
}
}
}
}
passOnwardsAs: "mergeBricksEntry"
)
@exportFrom(
scopedDynamicVariable: $mergeBricksEntry,
as: "mergeBricksImageElementImageEntries"
)
bricksSvgElementsData: bricksData( filterBy: { include: ["svg"] } )
@underEachArrayItem(
affectDirectivesUnderPos: [1, 2, 3]
passValueOnwardsAs: "bricksSvgElement"
)
@applyField(
name: "_objectProperty"
arguments: {
object: $bricksSvgElement,
by: { path: "settings.file.id" }
failIfNonExistingKeyOrPath: false
}
passOnwardsAs: "bricksSvgElementFileID"
)
# Dynamic data SVG elements have no ID
@applyField(
name: "_notNull"
arguments: {
value: $bricksSvgElementFileID
}
passOnwardsAs: "hasBricksSvgElementImageID"
)
@if(
condition: $hasBricksSvgElementImageID
affectDirectivesUnderPos: [1, 2, 3, 4, 5, 6, 7, 8]
)
@applyField(
name: "_objectProperty"
arguments: {
object: $bricksSvgElement,
by: { key: "id" }
}
passOnwardsAs: "elementID"
)
# `$bricksSvgElementFileID` it contains the ID of the image from staging, find the ID for production and create a new merge mutation entry
@applyField(
name: "_objectProperty"
arguments: {
object: $imageDataByID,
by: { key: $bricksSvgElementFileID }
}
passOnwardsAs: "externalImageData"
)
@applyField(
name: "_objectProperty"
arguments: {
object: $externalImageData,
by: { key: "slug" }
}
passOnwardsAs: "commonSlug"
)
@applyField(
name: "_objectProperty"
arguments: {
object: $localMediaItemDataBySlug,
by: { key: $commonSlug }
}
passOnwardsAs: "localImageData"
)
@applyField(
name: "_objectProperty"
arguments: {
object: $localImageData,
by: { key: "id" }
}
passOnwardsAs: "localImageID"
)
@applyField(
name: "_objectProperty"
arguments: {
object: $localImageData,
by: { key: "src" }
}
passOnwardsAs: "localImageSrc"
)
@applyField(
name: "_echo"
arguments: {
value: {
id: $elementID,
settings: {
file: {
id: $localImageID,
url: $localImageSrc
}
}
}
}
passOnwardsAs: "mergeBricksEntry"
)
@exportFrom(
scopedDynamicVariable: $mergeBricksEntry,
as: "mergeBricksSvgElementFileEntries"
)
bricksLogoElementsData: bricksData( filterBy: { include: ["logo"] } )
@underEachArrayItem(
affectDirectivesUnderPos: [1, 2, 3]
passValueOnwardsAs: "bricksLogoElement"
)
@applyField(
name: "_objectProperty"
arguments: {
object: $bricksLogoElement,
by: { path: "settings.logo.id" }
failIfNonExistingKeyOrPath: false
}
passOnwardsAs: "bricksLogoElementLogoID"
)
# External images have no ID
@applyField(
name: "_notNull"
arguments: {
value: $bricksLogoElementLogoID
}
passOnwardsAs: "hasBricksLogoElementLogoID"
)
@if(
condition: $hasBricksLogoElementLogoID
affectDirectivesUnderPos: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
)
@applyField(
name: "_objectProperty"
arguments: {
object: $bricksLogoElement,
by: { key: "id" }
}
passOnwardsAs: "elementID"
)
@applyField(
name: "_objectProperty"
arguments: {
object: $bricksLogoElement,
by: { path: "settings.logo.size" }
}
passOnwardsAs: "imageSize"
)
@applyField(
name: "_arraySearch",
arguments: {
array: $imageSizeNames
element: $imageSize
}
passOnwardsAs: "imageSizePosition"
)
# `$bricksLogoElementLogoID` it contains the ID of the image from staging, find the ID for production and create a new merge mutation entry
@applyField(
name: "_objectProperty"
arguments: {
object: $imageDataByID,
by: { key: $bricksLogoElementLogoID }
}
passOnwardsAs: "externalImageData"
)
@applyField(
name: "_objectProperty"
arguments: {
object: $externalImageData,
by: { key: "slug" }
}
passOnwardsAs: "commonSlug"
)
@applyField(
name: "_objectProperty"
arguments: {
object: $localMediaItemDataBySlug,
by: { key: $commonSlug }
}
passOnwardsAs: "localImageData"
)
@applyField(
name: "_objectProperty"
arguments: {
object: $localImageData,
by: { key: "id" }
}
passOnwardsAs: "localImageID"
)
@applyField(
name: "_objectProperty"
arguments: {
object: $localImageData,
by: { key: "srcs" }
}
passOnwardsAs: "localImageSrcs"
)
@applyField(
name: "_arrayItem"
arguments: {
array: $localImageSrcs,
position: $imageSizePosition
}
passOnwardsAs: "localImageSrc"
)
@applyField(
name: "_objectProperty"
arguments: {
object: $localImageData,
by: { key: "full" }
}
passOnwardsAs: "localImageFull"
)
@applyField(
name: "_echo"
arguments: {
value: {
id: $elementID,
settings: {
logo: {
id: $localImageID,
full: $localImageFull,
url: $localImageSrc
}
}
}
}
passOnwardsAs: "mergeBricksEntry"
)
@exportFrom(
scopedDynamicVariable: $mergeBricksEntry,
as: "mergeBricksLogoElementLogoEntries"
)
@underEachArrayItem(
affectDirectivesUnderPos: [1, 2, 3]
passValueOnwardsAs: "bricksLogoElement"
)
@applyField(
name: "_objectProperty"
arguments: {
object: $bricksLogoElement,
by: { path: "settings.logoInverse.id" }
failIfNonExistingKeyOrPath: false
}
passOnwardsAs: "bricksLogoElementLogoInverseID"
)
# External images have no ID
@applyField(
name: "_notNull"
arguments: {
value: $bricksLogoElementLogoInverseID
}
passOnwardsAs: "hasBricksLogoElementLogoInverseID"
)
@if(
condition: $hasBricksLogoElementLogoInverseID
affectDirectivesUnderPos: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
)
@applyField(
name: "_objectProperty"
arguments: {
object: $bricksLogoElement,
by: { key: "id" }
}
passOnwardsAs: "elementID"
)
@applyField(
name: "_objectProperty"
arguments: {
object: $bricksLogoElement,
by: { path: "settings.logoInverse.size" }
}
passOnwardsAs: "imageSize"
)
@applyField(
name: "_arraySearch",
arguments: {
array: $imageSizeNames
element: $imageSize
}
passOnwardsAs: "imageSizePosition"
)
# `$bricksLogoElementLogoInverseID` it contains the ID of the image from staging, find the ID for production and create a new merge mutation entry
@applyField(
name: "_objectProperty"
arguments: {
object: $imageDataByID,
by: { key: $bricksLogoElementLogoInverseID }
}
passOnwardsAs: "externalImageData"
)
@applyField(
name: "_objectProperty"
arguments: {
object: $externalImageData,
by: { key: "slug" }
}
passOnwardsAs: "commonSlug"
)
@applyField(
name: "_objectProperty"
arguments: {
object: $localMediaItemDataBySlug,
by: { key: $commonSlug }
}
passOnwardsAs: "localImageData"
)
@applyField(
name: "_objectProperty"
arguments: {
object: $localImageData,
by: { key: "id" }
}
passOnwardsAs: "localImageID"
)
@applyField(
name: "_objectProperty"
arguments: {
object: $localImageData,
by: { key: "srcs" }
}
passOnwardsAs: "localImageSrcs"
)
@applyField(
name: "_arrayItem"
arguments: {
array: $localImageSrcs,
position: $imageSizePosition
}
passOnwardsAs: "localImageSrc"
)
@applyField(
name: "_objectProperty"
arguments: {
object: $localImageData,
by: { key: "full" }
}
passOnwardsAs: "localImageFull"
)
@applyField(
name: "_echo"
arguments: {
value: {
id: $elementID,
settings: {
logoInverse: {
id: $localImageID,
full: $localImageFull,
url: $localImageSrc
}
}
}
}
passOnwardsAs: "mergeBricksEntry"
)
@exportFrom(
scopedDynamicVariable: $mergeBricksEntry,
as: "mergeBricksLogoElementLogoInverseEntries"
)
bricksImageGalleryElementsData: bricksData( filterBy: { include: ["image-gallery"] } )
@underEachArrayItem(
affectDirectivesUnderPos: [1, 2, 3, 4, 5, 6, 7, 8]
passValueOnwardsAs: "bricksImageGalleryElement"
)
@applyField(
name: "_objectProperty"
arguments: {
object: $bricksImageGalleryElement,
by: { key: "id" }
}
passOnwardsAs: "elementID"
)
@applyField(
name: "_objectProperty"
arguments: {
object: $bricksImageGalleryElement,
by: { path: "settings.items.size" }
}
passOnwardsAs: "imageSize"
)
@applyField(
name: "_arraySearch",
arguments: {
array: $imageSizeNames
element: $imageSize
}
passOnwardsAs: "imageSizePosition"
)
@applyField(
name: "_objectProperty"
arguments: {
object: $bricksImageGalleryElement,
by: { path: "settings.items.images" }
failIfNonExistingKeyOrPath: false
valueWhenNonExistingKeyOrPath: []
}
passOnwardsAs: "list"
)
@applyField(
name: "_arrayLength",
arguments: {
array: $list,
}
passOnwardsAs: "arrayLength"
)
@applyField(
name: "_echo",
arguments: {
value: {
id: $elementID,
length: $arrayLength,
}
}
passOnwardsAs: "elementProps"
)
@exportFrom(
scopedDynamicVariable: $elementProps
as: "computeBricksImageGalleryElementListElementProps"
)
@underJSONObjectProperty(
by: { path: "settings.items.images" }
failIfNonExistingKeyOrPath: false
)
@underEachArrayItem(
affectDirectivesUnderPos: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]
passValueOnwardsAs: "bricksImageGalleryElementListImage"
)
@exportFrom(
scopedDynamicVariable: $elementID,
as: "computeBricksImageGalleryElementListIDs"
)
@applyField(
name: "_objectProperty"
arguments: {
object: $bricksImageGalleryElementListImage,
by: { key: "id" }
failIfNonExistingKeyOrPath: false
}
passOnwardsAs: "bricksImageGalleryElementListImageID"
)
# `$bricksImageGalleryElementListImageID` it contains the ID of the image from staging, find the ID for production and create a new merge mutation entry
@applyField(
name: "_objectProperty"
arguments: {
object: $imageDataByID,
by: { key: $bricksImageGalleryElementListImageID }
}
passOnwardsAs: "externalImageData"
)
@applyField(
name: "_objectProperty"
arguments: {
object: $externalImageData,
by: { key: "slug" }
}
passOnwardsAs: "commonSlug"
)
@applyField(
name: "_objectProperty"
arguments: {
object: $localMediaItemDataBySlug,
by: { key: $commonSlug }
}
passOnwardsAs: "localImageData"
)
@applyField(
name: "_objectProperty"
arguments: {
object: $localImageData,
by: { key: "id" }
}
passOnwardsAs: "localImageID"
)
@applyField(
name: "_objectProperty"
arguments: {
object: $localImageData,
by: { key: "srcs" }
}
passOnwardsAs: "localImageSrcs"
)
@applyField(
name: "_arrayItem"
arguments: {
array: $localImageSrcs,
position: $imageSizePosition
}
passOnwardsAs: "localImageSrc"
)
@applyField(
name: "_objectProperty"
arguments: {
object: $localImageData,
by: { key: "full" }
}
passOnwardsAs: "localImageFull"
)
@applyField(
name: "_echo"
arguments: {
value: {
id: $localImageID,
full: $localImageFull,
url: $localImageSrc
}
}
passOnwardsAs: "entry"
)
@exportFrom(
scopedDynamicVariable: $entry,
as: "computeBricksImageGalleryElementListImageEntries"
)
}
}
query PrepareBricksImageData
@depends(on: "ExportBricksImageData")
{
mergeBricksImageGalleryElementImageEntries: _echo(value: $computeBricksImageGalleryElementListElementProps)
@underEachArrayItem(
passValueOnwardsAs: "elementProps"
affectDirectivesUnderPos: [1, 2, 3, 4, 6]
)
@applyField(
name: "_objectProperty",
arguments: {
object: $elementProps
by: { key: "id" }
}
passOnwardsAs: "elementID"
)
@applyField(
name: "_arraySearch",
arguments: {
array: $computeBricksImageGalleryElementListIDs
element: $elementID
}
passOnwardsAs: "offset"
)
@applyField(
name: "_notNull",
arguments: {
value: $offset
}
passOnwardsAs: "hasItems"
)
@unless(condition: $hasItems)
@setNull
@if(
condition: $hasItems
affectDirectivesUnderPos: [1, 2, 3]
)
@applyField(
name: "_objectProperty",
arguments: {
object: $elementProps
by: { key: "length" }
}
passOnwardsAs: "length"
)
@applyField(
name: "_arraySlice",
arguments: {
array: $computeBricksImageGalleryElementListImageEntries
length: $length,
offset: $offset
}
passOnwardsAs: "items"
)
@applyField(
name: "_echo",
arguments: {
value: {
id: $elementID,
settings: {
items: {
images: $items
}
}
}
},
setResultInResponse: true
)
@arrayFilter
@export(as: "mergeBricksImageGalleryElementImageEntries")
}
query CreateBricksImageDataMergeInputs
@depends(on: "PrepareBricksImageData")
{
mergeBricksEntries: _arrayMerge(
arrays: [
$mergeBricksAnyElementBackgroundImageEntries,
$mergeBricksImageElementImageEntries,
$mergeBricksSvgElementFileEntries,
$mergeBricksLogoElementLogoEntries,
$mergeBricksLogoElementLogoInverseEntries,
$mergeBricksImageGalleryElementImageEntries
]
)
bricksMergeCustomPostElementDataItemInputs: _echo(value: {
customPostID: $postId,
elements: $__mergeBricksEntries
})
@export(
as: "bricksMergeCustomPostElementDataItemInputs",
type: LIST
)
}
mutation MergeBricksImageData
@depends(on: "CreateBricksImageDataMergeInputs")
{
bricksMergeCustomPostElementDataItems(inputs: $bricksMergeCustomPostElementDataItemInputs) {
status
errors {
__typename
...on ErrorPayload {
message
@passOnwards(as: "message")
@fail(
message: $message
condition: ALWAYS
)
}
}
customPost {
__typename
...on CustomPost {
id
bricksData
}
}
}
}
""",
variables: [
{
name: "updateMediaItems",
value: $updateMediaItems
},
{
name: "postType",
value: $postType
},
{
name: "postSlug",
value: $postSlug
},
{
name: "postTitle",
value: $postTitle
},
{
name: "postContent",
value: $postContent
},
{
name: "postExcerpt",
value: $postExcerpt
},
{
name: "postStatus",
value: $postStatus
},
{
name: "featuredImageID",
value: $featuredImageID
},
{
name: "postDate",
value: $postDate
},
{
name: "postGmtDate",
value: $postGmtDate
},
{
name: "postMeta",
value: $postMeta
},
{
name: "imageData",
value: $imageData
},
],
options: {
headers: [
{
name: "Authorization",
value: $__loginCredentialsHeaderValue
}
]
}
}
)
}변수는 다음과 같이 지정합니다:
{
"postSlug": "my-bricks-page",
"prodSiteGraphQLEndpointURL": "https://production-site.com/graphql",
"username": "admin",
"appPassword": "your-app-password"
}