使用 Annict GraphQL 获取对观看的动漫的评论

练习GraphQL的同时,特别了解了联合类型,做了笔记。

有关Annict GraphQL API的官方解释在这里。
使用Annict的GraphQL API获取动漫数据 – Qiita

Annict API文档:https://docs.annict.com/ja/api/graphql/overview.html

简单地说,

我想要的是myuser.records[].episode.records(hasComment==true)[].comment。

GraphQL was developed by Facebook and is an open-source query language for APIs and a runtime for executing those queries with existing data. GraphQL is designed to improve efficiency and flexibility in fetching data from APIs by allowing clients to request specific data and minimizing the amount of data transferred over the network.

{
  viewer {
    records(first: 2) {
      edges {
        node {
          episode {
            work {
              title
            }
            records(first: 2, hasComment: true) {
              edges {
                node {
                  user {
                    name
                  }
                  comment
                  likesCount
                  createdAt
                  ratingState
                }
              }
            }
          }
        }
      }
    }
  }
}

部分回应

{
  "data": {
    "viewer": {
      "records": {
        "edges": [
          {
            "node": {
              "episode": {
                "work": {
                  "title": "ポプテピピック"
                },
                "records": {
                  "edges": [
                    {
                      "node": {
                        "user": {
                          "name": "うに"
                        },
                        "comment": "前半だけ",
                        "likesCount": 0,
                        "createdAt": "2018-02-18T05:09:28Z",
                        "ratingState": null
                      }
                    },
...

由于存在四种活动项,我在此指定了所需记录。

追加说明

由于API被扩展,我们进行了更新。

广告
将在 10 秒后关闭
bannerAds