Biblioteca de queries
Biblioteca de queriesReemplazar un slug de post antiguo por un slug nuevo en todos los posts

Reemplazar un slug de post antiguo por un slug nuevo en todos los posts

Después de cambiar el slug de un post, ejecuta esta consulta para convertir todo el contenido para apuntar a la nueva URL.

Esta consulta requiere que el endpoint tenga habilitadas las Mutaciones Anidadas.

query ExportData(
  $oldPostSlug: String!
  $newPostSlug: String!
) {
  siteURL: optionValue(name: "siteurl")
 
  oldPostURL: _strAppend(
    after: $__siteURL,
    append: $oldPostSlug
  ) @export(as: "oldPostURL")
 
  newPostURL: _strAppend(
    after: $__siteURL,
    append: $newPostSlug
  ) @export(as: "newPostURL")
}
 
mutation ReplaceOldWithNewSlugInPosts
  @depends(on: "ExportData")
{
  posts(
    filter: {
      search: $oldPostURL
    },
    pagination: {
      limit: -1
    }
  ) {
    id
    rawContent
    adaptedRawContent: _strReplace(
      search: $oldPostURL
      replaceWith: $newPostURL
      in: $__rawContent
    )
    update(input: {
      contentAs: { html: $__adaptedRawContent }
    }) {
      status
      errors {
        __typename
        ...on ErrorPayload {
          message
        }
      }
      post {
        id
        rawContent
      }
    }
  }
}