入门
入门替换 WPGraphQL

替换 WPGraphQL

如果您的应用程序正在使用 WPGraphQL,可以改为使用 Gato GraphQL。

WPGraphQL 与 Gato GraphQL 的 GraphQL schema 相似但略有不同,因此需要进行适配。

Next.js WordPress 入门模板 leoloso/next-wordpress-starter 可与 WPGraphQL 或 Gato GraphQL 任一服务器配合运行。该模板对两种服务器使用相同的 JS 逻辑,唯一不同的是 GraphQL queries。

该模板提供了多个在两种服务器之间适配 queries 的示例。例如,此 WPGraphQL query

fragment PostFields on Post {
  id
  categories {
    edges {
      node {
        databaseId
        id
        name
        slug
      }
    }
  }
  databaseId
  date
  isSticky
  postId
  slug
  title
}

...被如此适配为 Gato GraphQL 版本

fragment PostFields on Post {
  id
  categories: self {
    edges: categories(pagination: { limit: -1 }) {
      node: self {
        databaseId: id
        id
        name
        slug
      }
    }
  }
  databaseId: id
  date: dateStr
  isSticky
  postId: id
  slug
  title
}