Pustaka queries
Pustaka queriesRegex cari dan ganti beberapa string dalam sebuah post

Regex cari dan ganti beberapa string dalam sebuah post

Query ini mengambil sebuah post, mengganti semua kecocokan dari daftar string regex dengan daftar string dalam konten dan judul post, lalu menyimpan post tersebut kembali.

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
    }
  }
}