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 が拡張されたので更新しました。