mirror of
https://github.com/AnimeThemes/animethemes-api-docs.git
synced 2026-07-11 01:34:06 +02:00
docs(graphql): paginator suffix & singular queries (#119)
This commit is contained in:
@@ -7,20 +7,18 @@ title: Filter by External Site
|
||||
---
|
||||
|
||||
The AnimeThemes API provides an exclusive query for one of its most common use cases.
|
||||
The `findAnimesByExternalSite` query accepts three arguments to filter animes by external resources.
|
||||
An external resource may be linked to multiple animes.
|
||||
The `findAnimeByExternalSite` query accepts three arguments to filter anime by external resources.
|
||||
An external resource may be linked to multiple anime.
|
||||
|
||||
## Query Example
|
||||
|
||||
```graphql
|
||||
query ($id: Int!) {
|
||||
{
|
||||
findAnimesByExternalSite(site: ANILIST, id: $id) {
|
||||
name
|
||||
mediaFormat
|
||||
season
|
||||
year
|
||||
}
|
||||
findAnimeByExternalSite(site: ANILIST, id: $id) {
|
||||
name
|
||||
mediaFormat
|
||||
season
|
||||
year
|
||||
}
|
||||
}
|
||||
```
|
||||
@@ -42,7 +40,7 @@ None
|
||||
```json
|
||||
{
|
||||
"data": {
|
||||
"findAnimesByExternalSite": [
|
||||
"findAnimeByExternalSite": [
|
||||
{
|
||||
"name": "Hibike! Euphonium 3",
|
||||
"mediaFormat": "TV",
|
||||
|
||||
@@ -23,7 +23,7 @@ Most queries provide filtering arguments using the AND operator. Filtering argum
|
||||
Query example:
|
||||
```graphql
|
||||
query {
|
||||
animes(name_like: "%monogatari%") {
|
||||
animePaginator(name_like: "%monogatari%") {
|
||||
data {
|
||||
name
|
||||
}
|
||||
@@ -47,7 +47,7 @@ The argument is `trashed: Trashed`, which allows filtering to determine if trash
|
||||
|
||||
```graphql
|
||||
query {
|
||||
animes(trashed: ONLY) {
|
||||
animePaginator(trashed: ONLY) {
|
||||
data {
|
||||
name
|
||||
}
|
||||
@@ -61,14 +61,12 @@ Filtering in relationships is applied **ONLY** to the relationship and does not
|
||||
|
||||
```graphql
|
||||
query {
|
||||
animes {
|
||||
data {
|
||||
name
|
||||
animethemes(type: OP) {
|
||||
data {
|
||||
type
|
||||
sequence
|
||||
}
|
||||
anime(slug: "hibike_euphonium") {
|
||||
name
|
||||
animethemes(type: OP) {
|
||||
data {
|
||||
type
|
||||
sequence
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ The AnimeThemes API needs a `Content-Type` header.
|
||||
# A simple curl request works like this.
|
||||
curl -X POST
|
||||
-H "Content-Type: application/json"
|
||||
-d "{\"query\": \"{ animes { data { name } } }\"}"
|
||||
-d "{\"query\": \"{ animePaginator { data { name } } }\"}"
|
||||
https://graphql.animethemes.moe/
|
||||
```
|
||||
|
||||
@@ -28,12 +28,12 @@ curl -X POST
|
||||
|
||||
### Top Level
|
||||
|
||||
The AnimeThemes API specifies a custom `data` wrap for top-level members.
|
||||
The AnimeThemes API specifies a custom `data` wrap for top-level members that use pagination.
|
||||
|
||||
The following query
|
||||
```graphql
|
||||
query {
|
||||
animes {
|
||||
animePaginator {
|
||||
data {
|
||||
name
|
||||
}
|
||||
@@ -44,7 +44,7 @@ will return the JSON:
|
||||
```json
|
||||
{
|
||||
"data": {
|
||||
"animes": {
|
||||
"animePaginator": {
|
||||
"data": [
|
||||
{
|
||||
"name": ".hack//Liminality"
|
||||
@@ -54,4 +54,18 @@ will return the JSON:
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### Singular Query
|
||||
|
||||
In case you want to return a single object, there are a few types that allow it.
|
||||
The following example returns the first anime with the slug hibike_euphonium.
|
||||
|
||||
```graphql
|
||||
query {
|
||||
anime(slug: "hibike_euphonium") {
|
||||
name
|
||||
slug
|
||||
}
|
||||
}
|
||||
```
|
||||
@@ -8,6 +8,8 @@ title: Pagination
|
||||
|
||||
The AnimeThemes API query that uses pagination shall contain a `paginatorInfo` object for pagination strategies and a `data` collection with the resources.
|
||||
|
||||
The top-level fields that use pagination are singular and have the `Paginator` suffix.
|
||||
|
||||
|
||||
## Arguments
|
||||
|
||||
@@ -23,7 +25,7 @@ There are two arguments available for every query that uses pagination.
|
||||
The following query
|
||||
```graphql
|
||||
query {
|
||||
animes(first: 2, page: 1) {
|
||||
animePaginator(first: 2, page: 1) {
|
||||
paginatorInfo {
|
||||
count
|
||||
currentPage
|
||||
@@ -44,7 +46,7 @@ will return the JSON:
|
||||
```json
|
||||
{
|
||||
"data": {
|
||||
"animes": {
|
||||
"animePaginator": {
|
||||
"paginatorInfo": {
|
||||
"count": 2,
|
||||
"currentPage": 1,
|
||||
|
||||
@@ -16,7 +16,7 @@ A many-to-one relationship has an object that references the foreign type.
|
||||
|
||||
```graphql
|
||||
query {
|
||||
animethemes {
|
||||
animethemePaginator {
|
||||
data {
|
||||
sequence
|
||||
anime {
|
||||
@@ -33,13 +33,11 @@ A one-to-many relationship has a list of objects that reference the related type
|
||||
|
||||
```graphql
|
||||
query {
|
||||
animes {
|
||||
data {
|
||||
name
|
||||
animethemes(first: 2) {
|
||||
data {
|
||||
sequence
|
||||
}
|
||||
anime(slug: "hibike_euphonium") {
|
||||
name
|
||||
animethemes(first: 2) {
|
||||
data {
|
||||
sequence
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -66,24 +64,22 @@ Both fields `createdAt` and `updatedAt` are available for every many-to-many rel
|
||||
The following query
|
||||
```graphql
|
||||
query {
|
||||
animes {
|
||||
data {
|
||||
name
|
||||
resources {
|
||||
pageInfo { # Pagination
|
||||
total
|
||||
}
|
||||
nodes { # Without pivot fields
|
||||
anime(slug: "hibike_euphonium") {
|
||||
name
|
||||
resources {
|
||||
pageInfo { # Pagination
|
||||
total
|
||||
}
|
||||
nodes { # Without pivot fields
|
||||
link
|
||||
}
|
||||
edges { # With pivot fields
|
||||
node {
|
||||
link
|
||||
}
|
||||
edges { # With pivot fields
|
||||
node {
|
||||
link
|
||||
}
|
||||
as
|
||||
createdAt
|
||||
updatedAt
|
||||
}
|
||||
as
|
||||
createdAt
|
||||
updatedAt
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -93,35 +89,30 @@ will return the JSON:
|
||||
```json
|
||||
{
|
||||
"data": {
|
||||
"animes": {
|
||||
"data": [
|
||||
{
|
||||
"name": ".hack//Liminality",
|
||||
"resources": {
|
||||
"pageInfo": {
|
||||
"total": 6
|
||||
"anime": {
|
||||
"name": "Hibike! Euphonium",
|
||||
"resources": {
|
||||
"pageInfo": {
|
||||
"total": 9
|
||||
},
|
||||
"nodes": [
|
||||
{
|
||||
"link": "https://myanimelist.net/anime/27989"
|
||||
},
|
||||
...
|
||||
],
|
||||
"edges": [
|
||||
{
|
||||
"node": {
|
||||
"link": "https://myanimelist.net/anime/27989"
|
||||
},
|
||||
"nodes": [
|
||||
{
|
||||
"link": "https://myanimelist.net/anime/299"
|
||||
},
|
||||
...
|
||||
],
|
||||
"edges": [
|
||||
{
|
||||
"node": {
|
||||
"link": "https://myanimelist.net/anime/299"
|
||||
},
|
||||
"as": null,
|
||||
"createdAt": "2021-03-27T00:46:24+00:00",
|
||||
"updatedAt": "2021-03-27T00:46:24+00:00"
|
||||
}
|
||||
...
|
||||
]
|
||||
"as": null,
|
||||
"createdAt": "2021-03-26T21:49:16+00:00",
|
||||
"updatedAt": "2021-03-26T21:49:16+00:00"
|
||||
}
|
||||
}
|
||||
...
|
||||
]
|
||||
...
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -133,7 +124,7 @@ A union type indicates that a field might have multiple object types.
|
||||
|
||||
```graphql
|
||||
query {
|
||||
performances {
|
||||
performancePaginator {
|
||||
data {
|
||||
artist {
|
||||
... on Artist {
|
||||
@@ -159,7 +150,7 @@ The inverse relationship of polymorphic many-to-one. Applies pagination.
|
||||
|
||||
```graphql
|
||||
query {
|
||||
memberships {
|
||||
membershipPaginator {
|
||||
data {
|
||||
performances {
|
||||
data {
|
||||
|
||||
@@ -16,14 +16,14 @@ To sort in descending order, append `_DESC` to the field name.
|
||||
## Query
|
||||
|
||||
```graphql
|
||||
{
|
||||
animes(sort: NAME) { # Sorting in ascending direction.
|
||||
query {
|
||||
animePaginator(sort: NAME) { # Sorting in ascending direction.
|
||||
data {
|
||||
name
|
||||
}
|
||||
}
|
||||
|
||||
animes(sort: NAME_DESC) { # Sorting in descending direction.
|
||||
animePaginator(sort: NAME_DESC) { # Sorting in descending direction.
|
||||
data {
|
||||
name
|
||||
}
|
||||
@@ -36,13 +36,11 @@ To sort in descending order, append `_DESC` to the field name.
|
||||
It is possible to sort the relationships of the parent type.
|
||||
|
||||
```graphql
|
||||
{
|
||||
animes {
|
||||
data {
|
||||
resources(sort: EXTERNAL_ID) {
|
||||
nodes {
|
||||
externalId
|
||||
}
|
||||
query {
|
||||
anime(slug: "hibike_euphonium") {
|
||||
resources(sort: EXTERNAL_ID) {
|
||||
nodes {
|
||||
externalId
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -55,7 +53,7 @@ By providing a list of enum cases, the sort will be applied in the order of the
|
||||
|
||||
```graphql
|
||||
{
|
||||
animes(sort: [YEAR_DESC, SEASON]) {
|
||||
animePaginator(sort: [YEAR_DESC, SEASON]) {
|
||||
data {
|
||||
year
|
||||
season
|
||||
|
||||
Reference in New Issue
Block a user