Go to file
DrakeTDL 493d8244f8
update README.md
2023-10-10 20:37:19 -07:00
.vscode feat: replace most hand-crafted types with genereated types 2023-10-09 15:20:57 -07:00
examples add examples 2023-10-09 23:57:30 -07:00
graphql-codegen feat: replace most hand-crafted types with genereated types 2023-10-09 15:20:57 -07:00
src add some mutations for already implemented fields 2023-10-10 18:02:23 -07:00
.gitignore feat: replace most hand-crafted types with genereated types 2023-10-09 15:20:57 -07:00
README.md update README.md 2023-10-10 20:37:19 -07:00
TODO.md add: TODO.md 2023-10-07 00:01:18 -07:00
deno.json feat: replace most hand-crafted types with genereated types 2023-10-09 15:20:57 -07:00
mod.ts init 2023-10-06 23:26:33 -07:00

README.md

Anilist Wrapper

An UNOFFICIAL wrapper for the anilist api written in typescript.

You can visit the official graphql docs for anilist here to find out everything you can do1.

This wrapper is still in an early state. Interface may change.

Status

To see the current status of the wrapper check the todo list.

Installation

import { Client } from "https://gitlab.com/AnimeWatchingClub/anilist-api-wrapper/-/raw/master/mod.ts"

Usage

Creating a query

const query = Client().query.MediaList()

Query arguments

The queries can accept either an object of MediaListArguments.

const queryByUserName = Client().query.MediaList({ userName: "Josh" })
/*
query ($id: Int) {
    MediaList(id: $id) {
        id
    }
}
*/

const queryById = Client().query.MediaList({ id: 1 })
/*
query ($userName: String) {
    MediaList(userName: $userName) {
        id
    }
}
*/

Creating the query

Other Queries

Fetching without building the query

If you build the query and try to fetch it without telling which fields to return it will default to returning id to avoid errors.

const query = Client().query.MediaList({ userName: "Josh" })

await query.fetch()

=>

{
  "data": {
    "MediaList": {
      "id": 5318
    }
  }
}
Creating a complete search query

As the library follows the builder pattern you can just nest functions until you have every field you want.

const query = Client().query.MediaList({ userName: "Josh" }, (fields) => {
  fields.withId()
  fields.withUserId()
    .withPrivate()
    .withStartedAt((fields) => fields.withYear().withMonth().withDay())
    .withCompletedAt((fields) => fields.withYear().withMonth().withDay())
})

await query.fetch()

=>

{
  "data": {
    "MediaList": {
      "id": 5318,
      "userId": 1,
      "private": false,
      "startedAt": { "year": null, "month": null, "day": null },
      "completedAt": { "year": 2017, "month": 11, "day": 24 }
    }
  }
}

OAuth

Using Token

Once you have a token, you can pass it into Client({ token }).

Getting a token from an authorization code grant

This method allows you to convert the Authorization Code Grant into an access token. The response is a type Authorization.

const token = Client().auth.getToken({
  client_id: "<the id as a string>",
  client_secret: "<the client secret>",
  code: "<code>",
  redirect_uri: "<the redirect uri, this is required>",
})

=>

{
  "token_type": "string",
  /* A full year in seconds */
  "expires_in": "number",
  "access_token": "string",
  /* Currently not used for anything */
  "refresh_token": "string"
}

  1. Not everything is supported yet, please refer to the todo list to see what has full implementation or open an issue to talk about it ↩︎