Query 库在文章中搜索并替换多个字符串
在文章中搜索并替换多个字符串
此 query 检索一篇文章,将文章内容和标题中某个字符串列表的所有出现替换为另一个字符串列表,然后重新保存该文章。
query GetPostData(
$postId: ID!
$replaceFrom: [String!]!,
$replaceTo: [String!]!
) {
post(by: { id: $postId }, status: any) {
title
adaptedPostTitle: _strReplaceMultiple(
search: $replaceFrom
replaceWith: $replaceTo
in: $__title
)
@export(as: "adaptedPostTitle")
rawContent
adaptedRawContent: _strReplaceMultiple(
search: $replaceFrom
replaceWith: $replaceTo
in: $__rawContent
)
@export(as: "adaptedRawContent")
}
}
mutation SearchAndReplaceStringsInPost($postId: ID!)
@depends(on: "GetPostData")
{
updatePost(input: {
id: $postId,
title: $adaptedPostTitle,
contentAs: { html: $adaptedRawContent },
}) {
status
errors {
__typename
...on ErrorPayload {
message
}
}
post {
id
title
rawContent
}
}
}