Go to file
DrakeTDL a5913efeaa
init
2023-10-06 23:26:33 -07:00
.vscode init 2023-10-06 23:26:33 -07:00
src init 2023-10-06 23:26:33 -07:00
README.md init 2023-10-06 23:26:33 -07:00
deno.json init 2023-10-06 23:26:33 -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.

[[TOC]]

Status

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

Warning As of v0.12 the only way to create queries is query.<queryName>

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

The library provides 2 helpers methods for OAuth and i will explain them here

Using Token

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

Getting a token from an authorization code grant

This helper 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 ↩︎