LoginSignup
2
1

More than 5 years have passed since last update.

Annict GraphQL で視聴したアニメに対するコメントを取る

Last updated at Posted at 2018-02-05

GraphQL の練習がてらです。特に Union Type について知ったのでメモ。

Annict GraphQL API についての本家の解説はこちら。
AnnictのGraphQL APIを使ってアニメデータを取得しよう - Qiita

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

簡単に書くと

myuser.records[].episode.records(hasComment==true)[].comment が欲しいものです

GraphQL

{
  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
                      }
                    },
...

ActivityItemが4種類あるので今回欲しい Record を指定しています。

追記

API が拡張されたので更新しました。

2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1