Biblioteca de queriesExportar una entrada a otro sitio WordPress
Exportar una entrada a otro sitio WordPress
Esta consulta exporta una entrada desde este sitio WordPress hacia algún sitio WordPress downstream.
El plugin Gato GraphQL (versión gratuita) debe estar instalado en el sitio web downstream. Debe exponer un endpoint con "Nested mutations" habilitado.
El parámetro $update indica si se debe crear o actualizar una entrada en el sitio downstream.
Si se actualiza la entrada, el identificador común entre los sitios upstream y downstream es el slug de la entrada.
query CheckHasPost($postSlug: String!)
{
post(by: { slug: $postSlug }, status: any)
@fail(
message: "There is no post in the upstream site with the provided slug"
data: {
slug: $postSlug
}
)
{
rawTitle
@export(as: "postTitle")
rawContent
@export(as: "postContent")
}
isMissingPostInUpstream: _isNull(value: $__post)
@export(as: "isMissingPostInUpstream")
}
query ExportDownstreamGraphQLQuery
@depends(on: "CheckHasPost")
@skip(if: $isMissingPostInUpstream)
{
query: _echo(value: """
mutation LoginUserAndUpdatePost(
$update: Boolean! = false
$username: String!
$userPassword: String!
$postSlug: String!
$postTitle: String!
$postContent: String!
) {
loginUser(by: {
credentials: {
usernameOrEmail: $username,
password: $userPassword
}
}) {
userID
}
post(by: { slug: $postSlug }, status: any)
@include(if: $update)
{
update(input: {
title: $postTitle,
contentAs: { html: $postContent },
}) {
status
errors {
__typename
...on ErrorPayload {
message
}
}
post {
title
slug
content
status
}
}
}
createPost(input: {
title: $postTitle,
slug: $postSlug,
contentAs: { html: $postContent },
status: draft
})
@skip(if: $update)
{
status
errors {
__typename
...on ErrorPayload {
message
}
}
post {
title
slug
content
status
}
}
}
"""
)
@export(as: "query")
@remove
}
query ExportPostToWPSite(
$downstreamServerGraphQLEndpointURL: String!
$update: Boolean! = false
$username: String!
$userPassword: String!
$postSlug: String!
)
@depends(on: "ExportDownstreamGraphQLQuery")
@skip(if: $isMissingPostInUpstream)
{
_sendGraphQLHTTPRequest(
input: {
endpoint: $downstreamServerGraphQLEndpointURL,
query: $query,
variables: [
{
name: "update",
value: $update
},
{
name: "username",
value: $username
},
{
name: "userPassword",
value: $userPassword
},
{
name: "postSlug",
value: $postSlug
},
{
name: "postTitle",
value: $postTitle
},
{
name: "postContent",
value: $postContent
}
]
}
)
}