쿼리 라이브러리정규식으로 게시물 내 여러 문자열을 검색 및 교체하기
정규식으로 게시물 내 여러 문자열을 검색 및 교체하기
이 쿼리는 게시물을 가져와서, 게시물의 콘텐츠와 제목에서 정규식 문자열 목록과 일치하는 모든 항목을 문자열 목록으로 교체한 후, 게시물을 다시 저장합니다.
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
}
}
}Prev