Blog

⭐️ Phát hành v4.2 với mutations mới cho tags và categories, cải thiện mutations cho media, và tích hợp nâng cao với Polylang (PRO)

Leonardo Losoviz
Bởi Leonardo Losoviz ·

Gato GraphQL v4.2 đã được phát hành. Xem ghi chú phát hành trên GitHub để biết danh sách đầy đủ các thay đổi.

Dưới đây là các tính năng mới quan trọng nhất.

Thêm mutations cho tags và categories

Hiện có thể tạo, cập nhật và xóa post tags và categories, với các mutations mới được thêm vào:

  • PostCategory.delete
  • PostCategory.update
  • PostTag.delete
  • PostTag.update
  • Root.createPostCategory
  • Root.createPostTag
  • Root.deletePostCategory
  • Root.deletePostTag
  • Root.updatePostCategory
  • Root.updatePostTag

Và cả tags và categories tùy chỉnh, với các mutations mới được thêm vào:

  • GenericCategory.delete
  • GenericCategory.update
  • GenericTag.delete
  • GenericTag.update
  • Root.createCategory
  • Root.createTag
  • Root.deleteCategory
  • Root.deleteTag
  • Root.updateCategory
  • Root.updateTag

Query này tạo, cập nhật và xóa các post tag terms:

mutation CreateUpdateDeletePostTags {
  createPostTag(input: {
    name: "Some name"
    slug: "Some slug"
    description: "Some description"
  }) {
    status
    errors {
      __typename
      ...on ErrorPayload {
        message
      }
    }
    category {
      ...PostTagData
    }
  }
 
  updatePostTag(input: {
    id: 1
    name: "Some updated name"
    slug: "Some updated slug"
    description: "Some updated description"
  }) {
    status
    errors {
      __typename
      ...on ErrorPayload {
        message
      }
    }
    category {
      ...PostTagData
    }
  }
 
  deletePostTag(input: {
    id: 1
  }) {
    status
    errors {
      __typename
      ...on ErrorPayload {
        message
      }
    }
  }
}
 
fragment PostTagData on PostTag {
  id
  name
  slug
  description
}

Query này tạo, cập nhật và xóa các post category terms:

mutation CreateUpdateDeletePostCategories {
  createPostCategory(input: {
    name: "Some name"
    slug: "Some slug"
    description: "Some description"
  }) {
    status
    errors {
      __typename
      ...on ErrorPayload {
        message
      }
    }
    category {
      ...PostCategoryData
    }
  }
 
  updatePostCategory(input: {
    id: 1
    name: "Some updated name"
    slug: "Some updated slug"
    description: "Some updated description"
  }) {
    status
    errors {
      __typename
      ...on ErrorPayload {
        message
      }
    }
    category {
      ...PostCategoryData
    }
  }
 
  deletePostCategory(input: {
    id: 1
  }) {
    status
    errors {
      __typename
      ...on ErrorPayload {
        message
      }
    }
  }
}
 
fragment PostCategoryData on PostCategory {
  id
  name
  slug
  description
  parent {
    id
  }
}

Query này tạo, cập nhật và xóa các tag terms cho tag tùy chỉnh some-tag-taxonomy:

mutation CreateUpdateDeleteTags {
  createTag(input: {
    taxonomy: "some-tag-taxonomy",
    name: "Some name"
    slug: "Some slug"
    description: "Some description"
  }) {
    status
    errors {
      __typename
      ...on ErrorPayload {
        message
      }
    }
    category {
      ...TagData
    }
  }
 
  updateTag(input: {
    id: 1
    taxonomy: "some-tag-taxonomy"
    name: "Some updated name"
    slug: "Some updated slug"
    description: "Some updated description"
  }) {
    status
    errors {
      __typename
      ...on ErrorPayload {
        message
      }
    }
    category {
      ...TagData
    }
  }
 
  deleteTag(input: {
    id: 1
    taxonomy: "some-tag-taxonomy"
  }) {
    status
    errors {
      __typename
      ...on ErrorPayload {
        message
      }
    }
  }
}
 
fragment TagData on Tag {
  id
  name
  slug
  description
}

Query này tạo, cập nhật và xóa các category terms cho category tùy chỉnh some-cat-taxonomy:

mutation CreateUpdateDeleteCategories {
  createCategory(input: {
    taxonomy: "some-cat-taxonomy",
    name: "Some name"
    slug: "Some slug"
    description: "Some description"
  }) {
    status
    errors {
      __typename
      ...on ErrorPayload {
        message
      }
    }
    category {
      ...CategoryData
    }
  }
 
  updateCategory(input: {
    id: 1
    taxonomy: "some-cat-taxonomy"
    name: "Some updated name"
    slug: "Some updated slug"
    description: "Some updated description"
  }) {
    status
    errors {
      __typename
      ...on ErrorPayload {
        message
      }
    }
    category {
      ...CategoryData
    }
  }
 
  deleteCategory(input: {
    id: 1
    taxonomy: "some-cat-taxonomy"
  }) {
    status
    errors {
      __typename
      ...on ErrorPayload {
        message
      }
    }
  }
}
 
fragment CategoryData on Category {
  id
  name
  slug
  description
  parent {
    id
  }
}

Tạo media item bằng cách sử dụng tệp đính kèm từ media item hiện có

Mutation createMediaItem hiện có thể tạo một media item sử dụng cùng tệp đính kèm từ một media item hiện có (tức là không sao chép tệp trên đĩa):

mutation {
  createMediaItem(input: {
    from: {
      mediaItemBy: {
        id: 337
      }
    }
  }) {
    status
    errors {
      __typename
      ...on ErrorPayload {
        message
      }
    }
    mediaItem {
      id  # New media item created
      src # Same attachment as the provided media item
    }
  }
}

[PRO] Xác định ngôn ngữ Polylang trên mutations của tags và categories

Với tích hợp Polylang, khi tạo một tag hoặc category (xem ở trên), chúng ta có thể truyền input polylangLanguageBy để xác định ngôn ngữ của nó ngay từ đầu.

Ví dụ, query này tạo một post category và xác định ngôn ngữ của nó là Tiếng Tây Ban Nha:

mutation {
  createPostCategory(input: {
    name: "Noticias"
    polylangLanguageBy: { code: "es" }
  }) {
    status
    errors {
      __typename
      ...on ErrorPayload {
        message
      }
    }
    category {
      polylangLanguage {
        locale
      }
      name
    }
  }
}

[PRO] Thêm Polylang Mutations cho Media Items

Module PRO Polylang Mutations cung cấp mutations để tích hợp với plugin Polylang.

Schema GraphQL đã được mở rộng với các mutations để:

  • Thiết lập ngôn ngữ cho các media items, và
  • Xác định các liên kết giữa chúng (tức là chỉ ra rằng một tập hợp các media items là bản dịch của nhau).
MutationMô tả
polylangSetMediaItemLanguageĐặt ngôn ngữ cho media item.
polylangSaveMediaItemTranslationAssociationĐặt liên kết dịch thuật cho media item.

Ví dụ, query sau đây xác định ngôn ngữ cho 3 media items (thành Tiếng Anh, Tiếng Tây Ban Nha và Tiếng Pháp), và sau đó xác định rằng 3 media items này là bản dịch của nhau:

mutation {
  mediaItem1: polylangSetMediaItemLanguage(input: {id: 1007, languageBy: { code: "en" }}) {
    status
    errors {
      __typename
      ...on ErrorPayload {
        message
      }
    }
  }
  mediaItem2: polylangSetMediaItemLanguage(input: {id: 204, languageBy: { code: "es" }}) {
    status
    errors {
      __typename
      ...on ErrorPayload {
        message
      }
    }
  }
  mediaItem3: polylangSetMediaItemLanguage(input: {id: 377, languageBy: { code: "fr" }}) {
    status
    errors {
      __typename
      ...on ErrorPayload {
        message
      }
    }
  }
  polylangSaveMediaItemTranslationAssociation(input: {
    ids: [1007, 204, 377]
  }) {
    status
    errors {
      __typename
      ...on ErrorPayload {
        message
      }
    }
  }
}

[PRO] Lọc các thực thể theo ngôn ngữ mặc định của Polylang

Hiện có thể lọc các thực thể theo ngôn ngữ mặc định được đặt trong Polylang, bằng cách cung cấp giá trị enum DEFAULT trong bộ lọc polylangLanguagesBy:

{
  posts(
    filter: {
      polylangLanguagesBy: {
        predefined: DEFAULT
      }
    }
  ) {
    title
    polylangLanguage {
      code
    }
  }
 
  pages(
    filter: {
      polylangLanguagesBy: {
        predefined: DEFAULT
      }
    }
  ) {
    title
    polylangLanguage {
      code
    }
  }
 
  customPosts(
    filter: {
      polylangLanguagesBy: {
        predefined: DEFAULT
      }
      customPostTypes: "dummy-cpt"
    }
  ) {
    title
    polylangLanguage {
      code
    }
  }
}

[PRO] Automation: Lưu trữ phản hồi GraphQL trong nhật ký thông tin

Phản hồi GraphQL đầy đủ cho một lần thực thi automation (cho cả WP-Cron và Automation Rules, dù lần thực thi có thành công hay không) được ghi lại trong tệp wp-content/gatographql/logs/info.log.


Đăng ký nhận bản tin của chúng tôi

Cập nhật tất cả những điều mới từ Gato GraphQL.