aboutsummaryrefslogtreecommitdiff
path: root/lib/anilist/AniList.js
blob: b8d6ed3c66b27109bcb462099bf9b5332101cfa8 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
export async function aniListData({ sort, page = 1 }) {
  const resAnilist = await fetch(`https://graphql.anilist.co`, {
    method: "POST",
    headers: {
      "Content-Type": "application/json",
    },
    body: JSON.stringify({
      query: `
            query (
      $id: Int
      $page: Int
      $perPage: Int
      $search: String
      $sort: [MediaSort]
    ) {
      Page(page: $page, perPage: $perPage) {
        pageInfo {
          total
          currentPage
          lastPage
          hasNextPage
          perPage
        }
        media(id: $id, search: $search, sort: $sort type: ANIME) {
          id
          idMal
          status
          title {
            romaji
            english
          }
          bannerImage
          coverImage {
            extraLarge
            color
          }
          description
        }
      }
    }
  `,
      variables: {
        page: page,
        perPage: 15,
        sort,
      },
    }),
  });
  const anilistData = await resAnilist.json();
  const data = anilistData.data.Page.media;
  // console.log(resAnilist);
  return {
    props: {
      data,
    },
  };
}