ブログ

⭐️ v4.2リリース:タグ・カテゴリー向けの新しいmutation、メディア向けの改善されたmutation、Polylang統合の強化(PRO)

Leonardo Losoviz
著者: Leonardo Losoviz ·

Gato GraphQL v4.2 がリリースされました。変更の完全なリストについては、GitHubのリリースノートをご確認ください。

以下は、最も重要な新機能です。

タグとカテゴリー向けのmutationを追加

新たに追加されたmutationにより、投稿タグとカテゴリーの作成・更新・削除が可能になりました:

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

また、カスタムタグとカスタムカテゴリーについても、新たに追加されたmutationで対応しています:

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

このクエリは投稿タグのタームを作成・更新・削除します:

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
}

このクエリは投稿カテゴリーのタームを作成・更新・削除します:

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

このクエリは、カスタムタグ 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
}

このクエリは、カスタムカテゴリー 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] タグとカテゴリーのmutationでPolylang言語を指定

Polylang統合を使用すると、タグやカテゴリーを作成する際(上記参照)に polylangLanguageBy 入力を渡して、言語をあらかじめ定義することができます。

たとえば、このクエリは投稿カテゴリーを作成し、その言語をスペイン語として定義します:

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).
MutationDescription
polylangSetMediaItemLanguageSet the language of the media item.
polylangSaveMediaItemTranslationAssociationSet 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.


ニュースレターを購読する

Gato GraphQL のすべてのアップデートを把握しましょう。