博客

⭐️ 发布 v3.0,支持 WordPress 6.6 及批量 mutation

Leonardo Losoviz
作者:Leonardo Losoviz ·

Gato GraphQL v3.0 已发布,包含新功能以及若干破坏性变更。完整变更列表请查阅 GitHub 发布说明

以下是最重要的更新内容。

新增与 WordPress 6.6 的兼容性

Gato GraphQL 3.0 对所有区块进行了重新编译,以兼容 WordPress 6.6。(在之前的版本中,区块会抛出 JS 错误。)

新增批量 mutation 字段(适用于 schema 中的所有 mutation)

Gato GraphQL 3.0 为 schema 中的所有 mutation 添加了「批量」mutation 字段,允许一次性对多个资源执行 mutation。

例如,mutation createPosts(单资源 mutation 为 createPost)可创建多篇文章:

mutation CreatePosts {
  createPosts(inputs: [
    {
      title: "First post"
      contentAs: {
        html: "This is the content for the first post"
      }
    },
    {
      title: "Second post"
      contentAs: {
        html: "Here is another content, for another post"
      }
      excerpt: "The cup is within reach"
    },
    {
      title: "Third post"
      contentAs: {
        html: "This is yet another piece of content"
      },
      authorBy: {
        id: 1
      },
      status: draft
    }
  ]) {
    status
    errors {
      __typename
      ...on ErrorPayload {
        message
      }
    }
    post {
      id
      title
      content
      excerpt
      author {
        name
      }
      status
    }
  }
}

批量 mutation 为管理 WordPress 站点开启了更多可能性。例如,以下 GraphQL query 使用 createPosts(以及 Gato GraphQL PRO 提供的 Multiple Query Execution)来复制文章:

query ExportPostData
{
  postsToDuplicate: posts {
    rawTitle
    rawContent
    rawExcerpt
    postInput: _echo(value: {
      title: $__rawTitle
      contentAs: {
        html: $__rawContent
      },
      excerpt: $__rawExcerpt
    })
      @export(as: "postInputs", type: LIST)
      @remove
  }
}
 
mutation CreatePosts
  @depends(on: "ExportPostData")
{
  createPosts(inputs: $postInputs) {
    status
    errors {
      __typename
      ...on ErrorPayload {
        message
      }
    }
    post {
      id
      title
      content
      excerpt
    }
  }
}

新增的批量 mutation 字段列表如下:

  • Root.addCommentToCustomPosts
  • Root.createCustomPosts
  • Root.createMediaItems
  • Root.createPages
  • Root.createPosts
  • Root.removeFeaturedImageFromCustomPosts
  • Root.replyComments
  • Root.setCategoriesOnPosts
  • Root.setFeaturedImageOnCustomPosts
  • Root.setTagsOnPosts
  • Root.updateCustomPosts
  • Root.updatePages
  • Root.updatePosts
  • Comment.replyWithComments
  • CustomPost.addComments

破坏性变更:至少需要 WordPress v6.0

为支持 WordPress v6.6,插件中的区块必须以 WordPress v6.0+ 为目标重新编译。

因此,从 v3.0 起,Gato GraphQL 至少需要 WordPress v6.0

破坏性变更:schema 配置区块「Payload Types for Mutations」可能需要重新配置

schema 配置区块「Payload Types for Mutations」新增了一个选项值:「Do not use payload types for mutations (i.e. return the mutated entity)」。为此,其内部数据结构已发生变更。

如果您已创建了选择「Do not use payload types for mutations (i.e. return the mutated entity)」选项的 schema 配置,升级到 v3.0 后该选择值将丢失。您需要编辑 schema 配置,重新选择此选项并保存。


订阅我们的新闻通讯

及时了解 Gato GraphQL 的所有更新。