スキーマチュートリアルレッスン8: サイト移行
レッスン8: サイト移行
新しいドメインへの移行、別のURLへのページ移動などの際に、GraphQLクエリのバッチを実行してサイトのコンテンツを適応させることができます。
このGraphQLクエリが機能するには、エンドポイントに適用されたスキーマ設定でネストされたミューテーションが有効になっている必要があります。
新しいドメインへのコンテンツの適応
このGraphQLクエリは、まずコンテンツに "https://my-old-domain.com" を含む全投稿をフィルタリングし、この文字列を "https://my-new-domain.com" に置き換えます。
mutation ReplaceOldWithNewDomainInPosts {
posts(
filter: {
search: "https://my-old-domain.com"
}
) {
id
rawContent
adaptedRawContent: _strReplace(
search: "https://my-old-domain.com"
replaceWith: "https://my-new-domain.com"
in: $__rawContent
)
update(input: {
contentAs: { html: $__adaptedRawContent }
}) {
status
errors {
__typename
...on ErrorPayload {
message
}
}
post {
id
rawContent
}
}
}
}新しい投稿またはページURLへのコンテンツの適応
投稿またはページのスラッグを変更した後、すべてのコンテンツが新しいURLを指すように変換できます。
このGraphQLクエリはまず、WordPressの "siteurl" 設定からドメインを取得し、ページの古いURLと新しいURLを再構築します。
query ExportData(
$oldPageSlug: String!
$newPageSlug: String!
) {
siteURL: optionValue(name: "siteurl")
oldPageURL: _strAppend(
after: $__siteURL,
append: $oldPageSlug
) @export(as: "oldPageURL")
newPageURL: _strAppend(
after: $__siteURL,
append: $newPageSlug
) @export(as: "newPageURL")
}
mutation ReplaceOldWithNewURLInPosts
@depends(on: "ExportData")
{
posts(
filter: {
search: $oldPageURL
},
sort: { by: ID, order: ASC }
) {
id
rawContent
adaptedRawContent: _strReplace(
search: $oldPageURL
replaceWith: $newPageURL
in: $__rawContent
)
update(input: {
contentAs: { html: $__adaptedRawContent }
}) {
status
errors {
__typename
...on ErrorPayload {
message
}
}
post {
id
rawContent
}
}
}
}次に、variables ディクショナリを通じて古いページスラッグと新しいページスラッグを指定します。
{
"oldPageSlug": "/privacy/",
"newPageSlug": "/user-privacy/"
}