🏁 Ora puoi mutare i valori meta in Gato GraphQL
v11.3 di Gato GraphQL è stata rilasciata oggi, con il supporto per una funzionalità importante: Le mutazioni di meta!
Ora puoi aggiungere, aggiornare ed eliminare valori meta, per i custom post, i tag, le categorie, i commenti e gli utenti.
Di seguito alcuni esempi di queries che mutano i meta.
Aggiungere meta
Puoi aggiungere voci meta ai custom post, ai tag, alle categorie, ai commenti e agli utenti.
Questa query aggiunge una voce meta all'articolo con ID 4:
mutation {
addCustomPostMeta(input: {
id: 4
key: "some_key"
value: "Some value"
}) {
status
errors {
__typename
...on ErrorPayload {
message
}
}
customPost {
id
metaValue(key: "some_key")
}
}
}Questa query aggiunge la stessa chiave meta con valori diversi a diversi articoli, in blocco:
mutation {
addCustomPostMetas(inputs: [
{
id: 4
key: "some_key"
value: "Some value"
},
{
id: 5
key: "some_key"
value: "Some other value"
},
{
id: 6
key: "some_key"
value: "Yet another value"
}
]) {
status
errors {
__typename
...on ErrorPayload {
message
}
}
customPost {
id
metaValue(key: "some_key")
}
}
}Aggiornare meta
Aggiornare una voce meta di categoria:
mutation {
updateCategoryMeta(input: {
id: 20
key: "_source"
value: "Updated source value"
}) {
status
errors {
__typename
...on ErrorPayload {
message
}
}
category {
__typename
id
metaValue(key: "_source")
}
}
}Questa query utilizza nested mutations per aggiornare un valore meta in un articolo:
mutation {
post(by: {id: 1}) {
updateMeta(input: {
key: "some_key"
value: "Updated description"
}) {
status
errors {
__typename
...on ErrorPayload {
message
}
}
post {
id
metaValue(key: "single_meta_key")
}
}
}
}Eliminare meta
Eliminare una voce meta da un articolo:
mutation {
deletePostMeta(input: {
id: 5
key: "some_key"
}) {
status
errors {
__typename
...on ErrorPayload {
message
}
}
post {
id
metaValue(key: "some_key")
}
}
}Eliminare la stessa voce meta da più articoli, in blocco:
mutation {
deletePostMetas(inputs: [
{
id: 5
key: "some_key"
},
{
id: 6
key: "some_key"
}
]) {
status
errors {
__typename
...on ErrorPayload {
message
}
}
post {
id
metaValue(key: "some_key")
}
}
}Impostare più voci meta contemporaneamente
Puoi impostare più voci meta contemporaneamente passando un JSON alle diverse mutazioni set{Entity}Meta:
mutation {
setCustomPostMeta(input: {
id: 4
entries: {
single_meta_key: [
"This is a single entry",
],
object_meta_key: [
{
key: "This is a key",
value: "This is a value",
},
],
array_meta_key: [
"This is a string",
"This is another string",
],
object_array_meta_key: [
[
{
key: "This is a key 1",
value: "This is a value 1",
},
{
key: "This is a key 2",
value: "This is a value 2",
},
]
],
}
}) {
status
errors {
__typename
...on ErrorPayload {
message
}
}
customPost {
id
meta(keys: ["single_meta_key", "object_meta_key", "array_meta_key", "object_array_meta_key"])
}
}
}Impostare voci meta durante la creazione/aggiornamento di un'entità
Puoi definire voci meta direttamente durante la creazione o l'aggiornamento di un custom post, di un tag, di una categoria o di un commento, tramite il parametro meta.
Questa query imposta meta durante l'aggiunta di un commento:
mutation {
addCommentToCustomPost(input: {
customPostID: 1130
commentAs: { html: "New comment" }
meta: {
some_meta_key: [
"This is a single entry",
],
another_meta_key: [
"This is an array entry 1",
"This is an array entry 2",
],
}
}) {
status
errors {
__typename
...on ErrorPayload {
message
}
}
comment {
id
meta(keys: ["some_meta_key", "another_meta_key"])
}
}
}Questa query inietta il meta nella nested mutation Post.update:
mutation {
post(by: {id: 1}) {
update(input: {
meta: {
single_meta_key: [
"This is an updated value",
]
}
}) {
status
errors {
__typename
...on ErrorPayload {
message
}
}
post {
id
metaValue(key: "single_meta_key")
}
}
}
}