aboutsummaryrefslogtreecommitdiff
path: root/lib/AniList.js
diff options
context:
space:
mode:
Diffstat (limited to 'lib/AniList.js')
-rw-r--r--lib/AniList.js55
1 files changed, 55 insertions, 0 deletions
diff --git a/lib/AniList.js b/lib/AniList.js
new file mode 100644
index 0000000..2b65789
--- /dev/null
+++ b/lib/AniList.js
@@ -0,0 +1,55 @@
+export async function aniListData({ sort, page = 1 }) {
+ const resAnilist = await fetch(`https://graphql.anilist.co`, {
+ method: "POST",
+ headers: {
+ "Content-Type": "application/json",
+ Accept: "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
+ title {
+ romaji
+ english
+ }
+ coverImage {
+ extraLarge
+ }
+ description
+ }
+ }
+ }
+ `,
+ variables: {
+ page: page,
+ perPage: 15,
+ sort,
+ },
+ }),
+ });
+ const anilistData = await resAnilist.json();
+ const data = anilistData.data.Page.media;
+ // console.log(resAnilist);
+ return {
+ props: {
+ data,
+ },
+ };
+}