feat: initial commit for graphql api (#107)

This commit is contained in:
Kyrch
2025-06-06 20:58:39 +02:00
committed by Maniload
parent 47de7a5378
commit 6380af9a47
14 changed files with 964 additions and 563 deletions
+567 -543
View File
File diff suppressed because it is too large Load Diff
+96
View File
@@ -0,0 +1,96 @@
---
title: Global Search
---
# Global Search Query
The global search query returns a listing of resources that match a given search term.
## Query Example
```graphql
query ($search: String!) {
search(search: $search) {
anime {
name
}
artists {
name
}
animethemes {
type
}
playlists {
name
}
series {
name
}
songs {
title
}
studios {
name
}
videos {
basename
}
}
}
```
## Authentication
None
## Parameters
| Name | Type | Description |
| :----------: | :------: | :----------------------------- |
| page | Int | Index of the current page |
| perPage | Int | Number of items per page |
| search | String! | The term used for the search |
## Response
```json
{
search: {
anime: [
{
name: "name"
}
],
animethemes: [
{
type: "type"
}
],
artists: [
{
name: "name"
}
],
playlists: [
{
name: "name"
}
],
series: [
{
name: "name"
}
],
songs: [
{
title: "title"
}
],
videos: [
{
basename: "basename"
}
]
}
}
```
+11
View File
@@ -0,0 +1,11 @@
---
title: Filtering
---
# Filtering
---
// TODO
// Note: Waiting API refactor.
@@ -0,0 +1,57 @@
---
title: Getting Started
---
# Getting Started
---
The AnimeThemes API selectively implements the [**GraphQL Tool**](https://graphql.org).
Here we will provide an overview of where the AnimeThemes API adheres to or deviates from the specification.
It is recommended that you learn how to wrap a [GraphQL API](https://graphql.org/learn/).
## Content Negotiation
The AnimeThemes API needs a `Content-Type` header.
```powershell
# A simple curl request works like this.
curl -X POST
-H "Content-Type: application/json"
-d "{\"query\": \"{ animes { data { name } } }\"}"
https://graphql.animethemes.moe/
```
## Document Structure
### Top Level
The AnimeThemes API specifies a custom `data` wrap for top-level members.
The following query
```graphql
query {
animes {
data {
name
}
}
}
```
will return the JSON:
```json
{
"data": {
"animes": {
"data": [
{
"name": ".hack//Liminality"
},
...
]
}
}
}
```
+11
View File
@@ -0,0 +1,11 @@
---
title: Ordering
---
# Ordering
---
// TODO
// Note: Waiting API refactor.
+31
View File
@@ -0,0 +1,31 @@
---
title: Pagination
---
# Pagination
---
The AnimeThemes API query that uses pagination shall contain a `paginatorInfo` object for pagination strategies and a `data` collection with the resources.
```json
// The animes query contains a paginatorInfo object
{
"data": {
"animes": {
"paginatorInfo": {
"count": count,
"currentPage": currentPage,
"firstItem": firstItem,
"hasMorePages": hasMorePages,
"lastItem": lastItem,
"lastPage": lastPage,
"perPage": perPage,
"total": total
},
"data": [
...
]
}
}
}
+13
View File
@@ -0,0 +1,13 @@
---
title: Relationships
---
# Relationships
---
// TODO
## Many-to-Many
// TODO
+36
View File
@@ -0,0 +1,36 @@
---
title: Authentication
---
# Authentication
---
The AnimeThemes API uses token-based authentication to grant the user access to mutations.
## Token Authentication
The AnimeThemes API uses the [**Bearer authentication scheme**](https://www.rfc-editor.org/rfc/rfc6750.html) to validate requests for mutations.
The `Bearer` token in the `Authorization` request header must correspond to a valid API token.
```sh
# Returns the currently authenticated user
curl -X POST
-H "Content-Type: application/json"
-H "Authorization: Bearer {token}"
-d "{\"query\": \"{ me { name } }\"}"
https://graphql.animethemes.moe
```
## Status Codes
The AnimeThemes API uses framework-default response status codes for authenticated requests.
| Code | Description | Examples |
| :--: | :--------------------------------------------------- | :----------------: |
| 200 | OK - request succeeded | DELETE, PATCH, PUT |
| 201 | Created - new resource was created | POST |
| 401 | Unauthorized - invalid or no authentication provided | All |
| 403 | Forbidden - request is not authorized for user | All |
| 404 | Not Found - no resource was found | All |
+43
View File
@@ -0,0 +1,43 @@
---
title: Introduction
---
# Introduction
---
AnimeThemes is a simple and consistent repository of anime opening and ending themes. We provide direct links to high quality WebMs of your favorite OPs and EDs for your listening and discussion needs.
The AnimeThemes API provides access to our repository resources for your development needs.
## [GraphQL](/guide/intro/graphql/)
The AnimeThemes API selectively implements the [**GraphQL Tool**](https://graphql.org).
We provide an overview of where the AnimeThemes API adheres to or deviates from the specification.
## [Rate Limiting](/guide/intro/ratelimiting/)
The AnimeThemes API applies the standard named rate limiter of the Laravel Framework.
We provide an overview of managing request quotas.
## [Authentication](/guide/intro/authentication/)
The AnimeThemes API uses token-based authentication to grant the user access to mutations.
## [Validation](/guide/intro/validation/)
The AnimeThemes API uses form requests to validate query parameters.
## Terms of Use
The AnimeThemes API applies the [**AnimeThemes Terms of Service**](https://animethemes.moe/about/terms-of-service).
## Resources
For API support, please make use of the **#graphql** channel in the [**Discord Server**](https://discordapp.com/invite/m9zbVyQ).
To report an issue with or request a new feature for the API, please make use of the [**animethemes-server**](https://github.com/AnimeThemes/animethemes-server) Github.
To report an issue with or request a new feature for this documentation, please make use of the [**animethemes-api-docs**](https://github.com/AnimeThemes/animethemes-api-docs) Github.
+49
View File
@@ -0,0 +1,49 @@
---
title: Rate Limiting
---
# Rate Limiting
---
The AnimeThemes API applies the standard named rate limiter of the Laravel Framework.
Here we will provide an overview of managing request quotas.
## Response Headers
The AnimeThemes GraphQL API limits requests to 80 per minute.
The AnimeThemes API will return `X-RateLimit-Limit` and `X-RateLimit-Remaining` headers in the response.
```sh
...
X-RateLimit-Limit: 80
X-RateLimit-Remaining: 79
...
```
## Exceeding the Rate Limit
If the rate limit is exceeded, the AnimeThemes API will return `Retry-After` and `X-RateLimit-Reset` headers in the response.
```sh
...
X-RateLimit-Limit: 80
X-RateLimit-Remaining: 0
Retry-After: 60
X-RateLimit-Reset: 1625073463180
...
```
Additionally, the AnimeThemes API will return an error message in the response body.
```json
{
message: "Too Many Attempts."
}
```
## Query Complexity Limit
// TODO
+9
View File
@@ -0,0 +1,9 @@
---
title: Validation
---
# Validation
---
// TODO
+33
View File
@@ -0,0 +1,33 @@
---
title: Migrating from REST API
---
# Migrating from REST API
---
While writing the GraphQL API, it was decided to make some changes to follow the [best practices recommended by GraphQL](https://graphql.org/learn/best-practices/).
## Field names
Fields in the REST API are snake_case, but now it is camelCase instead.
Affected Fields:
* start_at -> startAt
* end_at -> endAt
* email_verified_at -> emailVerifiedAt
* two_factor_confirmed_at -> twoFactorConfirmedAt
* guard_name -> guardName
* media_format -> mediaFormat
* views_count -> viewsCount
* external_id -> externalId
* created_at -> createdAt
* updated_at -> updatedAt
* deleted_at -> deletedAt
## From Group to ThemeGroup
It is easy to confuse what a group is. They can be a group of animethemes (e.g. "English Version") or a group of artists (e.g. "Aqours").
The `group` query/type does not exist. For a group of animethemes, the query is `themegroups`. For a group of artists, they are included globally in the `artists` query.
+6 -18
View File
@@ -3,7 +3,7 @@ layout: home
hero:
name: AnimeThemes
text: API Documentation
text: GraphQL API Documentation
tagline: Access our repository of Anime opening and ending themes for your development needs
image:
light: /logo.svg
@@ -12,26 +12,14 @@ hero:
actions:
- theme: brand
text: Get Started
link: /intro/
link: /guide/intro/
- theme: alt
text: GraphiQL
link: https://graphql.animethemes.moe/graphiql
features:
- icon: 📻
title: Media Links
details: Embed or download audio and video using links provided by resources
link: /wiki/video/show/#response
linkText: Example
- icon: 🕸️
title: External Mappings
details: Find resources based on their mappings to sites like MyAnimeList or AniList
link: /intro/jsonapi/#has-filter
linkText: Example
- icon: 🔍
title: Advanced Querying
details: Support for randomization, searching and filtering by direct fields and relation fields out of the box
link: /intro/jsonapi/#filtering
linkText: Example
- icon: ✍️
title: Resource Management
details: Apply edits to our database (for users with requisite permissions)
link: /wiki/anime/store/
link: /guide/graphql/filtering/
linkText: Example
---
+2 -2
View File
@@ -1,7 +1,7 @@
{
"name": "animethemes-api-docs",
"version": "3.0.0",
"description": "AnimeThemes.moe API Documentation",
"version": "4.0.0",
"description": "AnimeThemes.moe GraphQL API Documentation",
"main": "index.js",
"authors": {
"name": "AnimeThemes",