Blog

⭐️ Rilasciata la v4.2 con nuove mutations per tag e categorie, mutations migliorate per i media e integrazione potenziata con Polylang (PRO)

Leonardo Losoviz
Di Leonardo Losoviz ·

Gato GraphQL v4.2 è stato rilasciato. Consulta le note di rilascio su GitHub per l'elenco completo delle modifiche.

Di seguito le nuove funzionalità più importanti.

Mutations aggiunte per tag e categorie

Ora è possibile creare, aggiornare ed eliminare tag e categorie degli articoli, con le mutations appena aggiunte:

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

E anche tag e categorie personalizzati, con le mutations appena aggiunte:

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

Questa query crea, aggiorna ed elimina i termini di post tag:

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
}

Questa query crea, aggiorna ed elimina i termini di post category:

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

Questa query crea, aggiorna ed elimina i termini di tag per un tag personalizzato 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
}

Questa query crea, aggiorna ed elimina i termini di categoria per una categoria personalizzata 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
  }
}

Creare un media item utilizzando l'allegato di un media item esistente

La mutation createMediaItem ora può creare un media item utilizzando lo stesso allegato di un media item esistente (ovvero senza duplicare il file su disco):

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] Definire la lingua Polylang nelle mutations di tag e categorie

Con l'integrazione Polylang, durante la creazione di un tag o di una categoria (vedi sopra), possiamo passare l'input polylangLanguageBy per definirne già la lingua.

Ad esempio, questa query crea una post category e ne definisce la lingua come spagnolo:

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

[PRO] Aggiunte le mutations Polylang per i Media Items

Il modulo PRO Polylang Mutations fornisce mutations per l'integrazione con il plugin Polylang.

Lo schema GraphQL è stato arricchito con mutations per:

  • Stabilire la lingua dei media items, e
  • Definire associazioni tra di essi (ovvero indicare che un insieme di media items è una traduzione l'uno dell'altro).
MutationDescrizione
polylangSetMediaItemLanguageImposta la lingua del media item.
polylangSaveMediaItemTranslationAssociationImposta l'associazione di traduzione per il media item.

Ad esempio, la seguente query definisce la lingua per 3 media items (in inglese, spagnolo e francese), e poi definisce che questi 3 media items sono una traduzione l'uno dell'altro:

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] Filtrare le entità per la lingua predefinita di Polylang

Ora è possibile filtrare le entità per la lingua predefinita impostata in Polylang, fornendo il valore enum DEFAULT nel filtro 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: Memorizzare la risposta GraphQL nei log informativi

La risposta GraphQL completa per un'esecuzione di automazione (sia per WP-Cron che per le Automation Rules, indipendentemente dal fatto che l'esecuzione sia andata a buon fine o meno) viene registrata nel file wp-content/gatographql/logs/info.log.


Iscriviti alla nostra newsletter

Resta aggiornato su tutte le novità di Gato GraphQL.