⭐️ เปิดตัว v4.2 พร้อม mutation ใหม่สำหรับแท็กและหมวดหมู่ mutation ที่ปรับปรุงสำหรับสื่อ และการผสานรวมกับ Polylang ที่ดียิ่งขึ้น (PRO)
Gato GraphQL v4.2 ได้เปิดตัวแล้ว ดูรายการการเปลี่ยนแปลงทั้งหมดได้ที่ release notes ใน GitHub
ด้านล่างนี้คือฟีเจอร์ใหม่ที่สำคัญที่สุด
เพิ่ม mutation สำหรับแท็กและหมวดหมู่
ตอนนี้สามารถสร้าง อัปเดต และลบแท็กและหมวดหมู่ของโพสต์ได้แล้ว ด้วย mutation ที่เพิ่มเข้ามาใหม่:
PostCategory.deletePostCategory.updatePostTag.deletePostTag.updateRoot.createPostCategoryRoot.createPostTagRoot.deletePostCategoryRoot.deletePostTagRoot.updatePostCategoryRoot.updatePostTag
และยังรองรับแท็กและหมวดหมู่แบบกำหนดเอง ด้วย mutation ที่เพิ่มเข้ามาใหม่:
GenericCategory.deleteGenericCategory.updateGenericTag.deleteGenericTag.updateRoot.createCategoryRoot.createTagRoot.deleteCategoryRoot.deleteTagRoot.updateCategoryRoot.updateTag
query นี้สร้าง อัปเดต และลบ term ของแท็กโพสต์:
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 นี้สร้าง อัปเดต และลบ term ของหมวดหมู่โพสต์:
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 นี้สร้าง อัปเดต และลบ term ของแท็กสำหรับแท็กแบบกำหนดเอง 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 นี้สร้าง อัปเดต และลบ term ของหมวดหมู่สำหรับหมวดหมู่แบบกำหนดเอง 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
}
}สร้างมีเดียไอเทมโดยใช้ไฟล์แนบจากมีเดียไอเทมที่มีอยู่แล้ว
createMediaItem mutation สามารถสร้างมีเดียไอเทมโดยใช้ไฟล์แนบเดียวกันกับมีเดียไอเทมที่มีอยู่แล้วได้ (กล่าวคือ โดยไม่ต้องทำสำเนาไฟล์ลงบนดิสก์):
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] กำหนดภาษา Polylang ใน mutation ของแท็กและหมวดหมู่
ด้วยการผสานรวมกับ Polylang เมื่อสร้างแท็กหรือหมวดหมู่ (ดูด้านบน) เราสามารถส่ง input polylangLanguageBy เพื่อกำหนดภาษาของมันไว้ล่วงหน้าได้
ตัวอย่างเช่น query นี้สร้างหมวดหมู่โพสต์ และกำหนดภาษาเป็นภาษาสเปน:
mutation {
createPostCategory(input: {
name: "Noticias"
polylangLanguageBy: { code: "es" }
}) {
status
errors {
__typename
...on ErrorPayload {
message
}
}
category {
polylangLanguage {
locale
}
name
}
}
}[PRO] Added Polylang Mutations for Media Items
PRO module Polylang Mutations provides mutations for the integration with the Polylang plugin.
The GraphQL schema has been augmented with mutations to:
- Establish the language for media items, and
- Define associations among them (i.e. indicate that a set of media items is a translation for each other).
| Mutation | Description |
|---|---|
polylangSetMediaItemLanguage | Set the language of the media item. |
polylangSaveMediaItemTranslationAssociation | Set the translation association for the media item. |
For instance, the following query defines the language for 3 media items (to English, Spanish and French), and then defines that these 3 media items are a translation of each other:
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] Filter entities by Polylang's default language
It's now possible to filter entities by default language set on Polylang, by providing the DEFAULT enum value on the polylangLanguagesBy filter:
{
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: Store the GraphQL response in the info logs
The complete GraphQL response for an automation execution (for both WP-Cron and Automation Rules, whether the execution was successful or not) is logged under file wp-content/gatographql/logs/info.log.