Queryライブラリ正規表現で投稿内の複数の文字列を検索・置換する
正規表現で投稿内の複数の文字列を検索・置換する
このクエリは投稿を取得し、投稿のコンテンツとタイトルにおいて正規表現文字列のリストに一致するすべての箇所を文字列のリストで置換し、投稿を再度保存します。
query GetPostData(
$postId: ID!
$searchRegex: [String!]!,
$replaceWith: [String!]!
) {
post(by: { id: $postId }, status: any) {
title
adaptedPostTitle: _strRegexReplaceMultiple(
searchRegex: $searchRegex
replaceWith: $replaceWith
in: $__title
)
@export(as: "adaptedPostTitle")
rawContent
adaptedRawContent: _strRegexReplaceMultiple(
searchRegex: $searchRegex
replaceWith: $replaceWith
in: $__rawContent
)
@export(as: "adaptedRawContent")
}
}
mutation RegexSearchAndReplaceStringsInPost($postId: ID!)
@depends(on: "GetPostData")
{
updatePost(input: {
id: $postId,
title: $adaptedPostTitle,
contentAs: { html: $adaptedRawContent },
}) {
status
errors {
__typename
...on ErrorPayload {
message
}
}
post {
id
title
rawContent
}
}
}