Export post to WordPress site

🔥 This query is already included in Gato GraphQL, as Persisted Query “Export post to WordPress site”.

This query exports a post from this WordPress site into some downstream WordPress site.

The Gato GraphQL plugin (free version) must be installed on the downstream website. It must expose an endpoint with "Nested mutations" enabled.

The $update parameter indicates if to create or update a post in the downstream site.

If updating the post, the common identifier between the upstream and downstream sites is the post slug.

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

Extensions required for this query permalink

  1. Field on Field permalink

    Manipulate the value of a field by applying some other field on it.

  2. Field Response Removal permalink

    Remove the output of a field from the response.

  3. Field To Input permalink

    Retrieve the value of a field, manipulate it, and input it into another field or directive, all within the same operation.

  4. Field Value Iteration and Manipulation permalink

    Iterate and manipulate the value elements of array and object fields.

  5. HTTP Client permalink

    Addition of fields to execute HTTP requests against a webserver and fetch their response.

  6. Multiple Query Execution permalink

    Combine multiple queries into a single query, sharing state across them and executing them in the requested order.

  7. PHP Functions via Schema permalink

    Manipulate the field output using standard programming language functions available in PHP.

  8. Response Error Trigger permalink

    Explicitly add an error entry to the response to trigger the failure of the GraphQL request (whenever a field does not meet the expected conditions).

Bundles containing all extensions required for this query permalink

  1. “All in One Toolbox for WordPress” Bundle permalink

    Achieve all superpowers: All of Gato GraphQL extensions, in a single plugin

  2. “Automated Content Translation & Sync for WordPress Multisite” Bundle permalink

    Automatically create a translation of a newly-published post using the Google Translate API, for every language site on a WordPress multisite

  3. “Better WordPress Webhooks” Bundle permalink

    Easily create webhooks to process incoming data from any source or service using advanced tools, directly within the wp-admin

  4. “Private GraphQL Server for WordPress” Bundle permalink

    Use GraphQL to power your application (blocks, themes and plugins), internally fetching data without exposing a public endpoint

  5. “Selective Content Import, Export & Sync for WordPress” Bundle permalink

    Import hundreds of records into your WordPress site from another site or service (such as Google Sheets), and selectively export entries to another site

  6. “Tailored WordPress Automator” Bundle permalink

    Create workflows to automate tasks (to transform data, automatically caption images, send notifications, and more)

  7. “Versatile WordPress Request API” Bundle permalink

    Interact with any external API and cloud service, posting and fetching data to/from them

Tutorial lessons explaining how the query works permalink