Queries Kütüphanesi
Queries KütüphanesiWordPress sitesine gönderi aktar

WordPress sitesine gönderi aktar

Bu query, bu WordPress sitesindeki bir gönderiyi aşağı akış WordPress sitesine aktarır.

Gato GraphQL eklentisinin (ücretsiz sürüm) aşağı akış web sitesine kurulu olması gerekir. "Nested mutations" etkinleştirilmiş bir endpoint sunmalıdır.

$update parametresi, aşağı akış sitesinde bir gönderinin oluşturulup oluşturulmayacağını veya güncelleneceğini belirtir.

Gönderi güncelleniyorsa, yukarı akış ve aşağı akış siteleri arasındaki ortak tanımlayıcı gönderi slug'udur.

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