Blog

🏁 Artık Gato GraphQL'de meta değerlerini değiştirebilirsiniz

Leonardo Losoviz
Yazan: Leonardo Losoviz ·

Gato GraphQL'in v11.3 sürümü bugün yayınlandı; önemli bir özellik olan: Meta mutations desteğiyle!

Artık custom post'lar, etiketler, kategoriler, yorumlar ve kullanıcılar için meta değerlerini ekleyebilir, güncelleyebilir ve silebilirsiniz.

Aşağıda meta'yı değiştiren queries örnekleri verilmektedir.

Meta ekleme

Custom post'lara, etiketlere, kategorilere, yorumlara ve kullanıcılara meta girişi ekleyebilirsiniz.

Bu query, ID'si 4 olan gönderiye bir meta girişi ekler:

mutation {
  addCustomPostMeta(input: {
    id: 4
    key: "some_key"
    value: "Some value"
  }) {
    status
    errors {
      __typename
      ...on ErrorPayload {
        message
      }
    }
    customPost {
      id
      metaValue(key: "some_key") 
    }
  }
}

Bu query, aynı meta anahtarını farklı değerlerle birden fazla gönderiye toplu olarak ekler:

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

Meta güncelleme

Bir kategori meta girişini güncelleyin:

mutation {
  updateCategoryMeta(input: {
    id: 20
    key: "_source"
    value: "Updated source value"
  }) {
    status
    errors {
      __typename
      ...on ErrorPayload {
        message
      }
    }
    category {
      __typename
      id
      metaValue(key: "_source") 
    }
  }
}

Bu query, bir gönderideki meta değerini güncellemek için nested mutations kullanır:

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

Meta silme

Bir gönderiden meta girişini silin:

mutation {
  deletePostMeta(input: {
    id: 5
    key: "some_key"
  }) {
    status
    errors {
      __typename
      ...on ErrorPayload {
        message
      }
    }
    post {
      id
      metaValue(key: "some_key") 
    }
  }
}

Aynı meta girişini birden fazla gönderiden toplu olarak silin:

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

Aynı anda birden fazla meta girişi ayarlama

Farklı set{Entity}Meta mutations'larına JSON ileterek aynı anda birden fazla meta girişi ayarlayabilirsiniz:

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"])
    }
  }
}

Bir varlık oluşturulurken/güncellenirken meta girişleri ayarlama

Bir custom post, etiket, kategori veya yorum oluştururken ya da güncellerken meta parametresi aracılığıyla meta girişlerini doğrudan tanımlayabilirsiniz.

Bu query, bir yorum eklerken meta ayarlar:

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"]) 
    }
  }
}

Bu query, meta'yı Post.update nested mutation'ına enjekte eder:

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

Bültenimize abone olun

Gato GraphQL'deki tüm güncellemelerden haberdar olun.