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 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.
|
The `findAnimeByExternalSite` query accepts three arguments to filter anime by external resources.
|
||||||
An external resource may be linked to multiple animes.
|
An external resource may be linked to multiple anime.
|
||||||
|
|
||||||
## Query Example
|
## Query Example
|
||||||
|
|
||||||
```graphql
|
```graphql
|
||||||
query ($id: Int!) {
|
query ($id: Int!) {
|
||||||
{
|
findAnimeByExternalSite(site: ANILIST, id: $id) {
|
||||||
findAnimesByExternalSite(site: ANILIST, id: $id) {
|
name
|
||||||
name
|
mediaFormat
|
||||||
mediaFormat
|
season
|
||||||
season
|
year
|
||||||
year
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
@@ -42,7 +40,7 @@ None
|
|||||||
```json
|
```json
|
||||||
{
|
{
|
||||||
"data": {
|
"data": {
|
||||||
"findAnimesByExternalSite": [
|
"findAnimeByExternalSite": [
|
||||||
{
|
{
|
||||||
"name": "Hibike! Euphonium 3",
|
"name": "Hibike! Euphonium 3",
|
||||||
"mediaFormat": "TV",
|
"mediaFormat": "TV",
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ Most queries provide filtering arguments using the AND operator. Filtering argum
|
|||||||
Query example:
|
Query example:
|
||||||
```graphql
|
```graphql
|
||||||
query {
|
query {
|
||||||
animes(name_like: "%monogatari%") {
|
animePaginator(name_like: "%monogatari%") {
|
||||||
data {
|
data {
|
||||||
name
|
name
|
||||||
}
|
}
|
||||||
@@ -47,7 +47,7 @@ The argument is `trashed: Trashed`, which allows filtering to determine if trash
|
|||||||
|
|
||||||
```graphql
|
```graphql
|
||||||
query {
|
query {
|
||||||
animes(trashed: ONLY) {
|
animePaginator(trashed: ONLY) {
|
||||||
data {
|
data {
|
||||||
name
|
name
|
||||||
}
|
}
|
||||||
@@ -61,14 +61,12 @@ Filtering in relationships is applied **ONLY** to the relationship and does not
|
|||||||
|
|
||||||
```graphql
|
```graphql
|
||||||
query {
|
query {
|
||||||
animes {
|
anime(slug: "hibike_euphonium") {
|
||||||
data {
|
name
|
||||||
name
|
animethemes(type: OP) {
|
||||||
animethemes(type: OP) {
|
data {
|
||||||
data {
|
type
|
||||||
type
|
sequence
|
||||||
sequence
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ The AnimeThemes API needs a `Content-Type` header.
|
|||||||
# A simple curl request works like this.
|
# A simple curl request works like this.
|
||||||
curl -X POST
|
curl -X POST
|
||||||
-H "Content-Type: application/json"
|
-H "Content-Type: application/json"
|
||||||
-d "{\"query\": \"{ animes { data { name } } }\"}"
|
-d "{\"query\": \"{ animePaginator { data { name } } }\"}"
|
||||||
https://graphql.animethemes.moe/
|
https://graphql.animethemes.moe/
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -28,12 +28,12 @@ curl -X POST
|
|||||||
|
|
||||||
### Top Level
|
### 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
|
The following query
|
||||||
```graphql
|
```graphql
|
||||||
query {
|
query {
|
||||||
animes {
|
animePaginator {
|
||||||
data {
|
data {
|
||||||
name
|
name
|
||||||
}
|
}
|
||||||
@@ -44,7 +44,7 @@ will return the JSON:
|
|||||||
```json
|
```json
|
||||||
{
|
{
|
||||||
"data": {
|
"data": {
|
||||||
"animes": {
|
"animePaginator": {
|
||||||
"data": [
|
"data": [
|
||||||
{
|
{
|
||||||
"name": ".hack//Liminality"
|
"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 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
|
## Arguments
|
||||||
|
|
||||||
@@ -23,7 +25,7 @@ There are two arguments available for every query that uses pagination.
|
|||||||
The following query
|
The following query
|
||||||
```graphql
|
```graphql
|
||||||
query {
|
query {
|
||||||
animes(first: 2, page: 1) {
|
animePaginator(first: 2, page: 1) {
|
||||||
paginatorInfo {
|
paginatorInfo {
|
||||||
count
|
count
|
||||||
currentPage
|
currentPage
|
||||||
@@ -44,7 +46,7 @@ will return the JSON:
|
|||||||
```json
|
```json
|
||||||
{
|
{
|
||||||
"data": {
|
"data": {
|
||||||
"animes": {
|
"animePaginator": {
|
||||||
"paginatorInfo": {
|
"paginatorInfo": {
|
||||||
"count": 2,
|
"count": 2,
|
||||||
"currentPage": 1,
|
"currentPage": 1,
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ A many-to-one relationship has an object that references the foreign type.
|
|||||||
|
|
||||||
```graphql
|
```graphql
|
||||||
query {
|
query {
|
||||||
animethemes {
|
animethemePaginator {
|
||||||
data {
|
data {
|
||||||
sequence
|
sequence
|
||||||
anime {
|
anime {
|
||||||
@@ -33,13 +33,11 @@ A one-to-many relationship has a list of objects that reference the related type
|
|||||||
|
|
||||||
```graphql
|
```graphql
|
||||||
query {
|
query {
|
||||||
animes {
|
anime(slug: "hibike_euphonium") {
|
||||||
data {
|
name
|
||||||
name
|
animethemes(first: 2) {
|
||||||
animethemes(first: 2) {
|
data {
|
||||||
data {
|
sequence
|
||||||
sequence
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -66,24 +64,22 @@ Both fields `createdAt` and `updatedAt` are available for every many-to-many rel
|
|||||||
The following query
|
The following query
|
||||||
```graphql
|
```graphql
|
||||||
query {
|
query {
|
||||||
animes {
|
anime(slug: "hibike_euphonium") {
|
||||||
data {
|
name
|
||||||
name
|
resources {
|
||||||
resources {
|
pageInfo { # Pagination
|
||||||
pageInfo { # Pagination
|
total
|
||||||
total
|
}
|
||||||
}
|
nodes { # Without pivot fields
|
||||||
nodes { # Without pivot fields
|
link
|
||||||
|
}
|
||||||
|
edges { # With pivot fields
|
||||||
|
node {
|
||||||
link
|
link
|
||||||
}
|
}
|
||||||
edges { # With pivot fields
|
as
|
||||||
node {
|
createdAt
|
||||||
link
|
updatedAt
|
||||||
}
|
|
||||||
as
|
|
||||||
createdAt
|
|
||||||
updatedAt
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -93,35 +89,30 @@ will return the JSON:
|
|||||||
```json
|
```json
|
||||||
{
|
{
|
||||||
"data": {
|
"data": {
|
||||||
"animes": {
|
"anime": {
|
||||||
"data": [
|
"name": "Hibike! Euphonium",
|
||||||
{
|
"resources": {
|
||||||
"name": ".hack//Liminality",
|
"pageInfo": {
|
||||||
"resources": {
|
"total": 9
|
||||||
"pageInfo": {
|
},
|
||||||
"total": 6
|
"nodes": [
|
||||||
|
{
|
||||||
|
"link": "https://myanimelist.net/anime/27989"
|
||||||
|
},
|
||||||
|
...
|
||||||
|
],
|
||||||
|
"edges": [
|
||||||
|
{
|
||||||
|
"node": {
|
||||||
|
"link": "https://myanimelist.net/anime/27989"
|
||||||
},
|
},
|
||||||
"nodes": [
|
"as": null,
|
||||||
{
|
"createdAt": "2021-03-26T21:49:16+00:00",
|
||||||
"link": "https://myanimelist.net/anime/299"
|
"updatedAt": "2021-03-26T21:49:16+00:00"
|
||||||
},
|
|
||||||
...
|
|
||||||
],
|
|
||||||
"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"
|
|
||||||
}
|
|
||||||
...
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
}
|
...
|
||||||
...
|
]
|
||||||
]
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -133,7 +124,7 @@ A union type indicates that a field might have multiple object types.
|
|||||||
|
|
||||||
```graphql
|
```graphql
|
||||||
query {
|
query {
|
||||||
performances {
|
performancePaginator {
|
||||||
data {
|
data {
|
||||||
artist {
|
artist {
|
||||||
... on Artist {
|
... on Artist {
|
||||||
@@ -159,7 +150,7 @@ The inverse relationship of polymorphic many-to-one. Applies pagination.
|
|||||||
|
|
||||||
```graphql
|
```graphql
|
||||||
query {
|
query {
|
||||||
memberships {
|
membershipPaginator {
|
||||||
data {
|
data {
|
||||||
performances {
|
performances {
|
||||||
data {
|
data {
|
||||||
|
|||||||
@@ -16,14 +16,14 @@ To sort in descending order, append `_DESC` to the field name.
|
|||||||
## Query
|
## Query
|
||||||
|
|
||||||
```graphql
|
```graphql
|
||||||
{
|
query {
|
||||||
animes(sort: NAME) { # Sorting in ascending direction.
|
animePaginator(sort: NAME) { # Sorting in ascending direction.
|
||||||
data {
|
data {
|
||||||
name
|
name
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
animes(sort: NAME_DESC) { # Sorting in descending direction.
|
animePaginator(sort: NAME_DESC) { # Sorting in descending direction.
|
||||||
data {
|
data {
|
||||||
name
|
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.
|
It is possible to sort the relationships of the parent type.
|
||||||
|
|
||||||
```graphql
|
```graphql
|
||||||
{
|
query {
|
||||||
animes {
|
anime(slug: "hibike_euphonium") {
|
||||||
data {
|
resources(sort: EXTERNAL_ID) {
|
||||||
resources(sort: EXTERNAL_ID) {
|
nodes {
|
||||||
nodes {
|
externalId
|
||||||
externalId
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -55,7 +53,7 @@ By providing a list of enum cases, the sort will be applied in the order of the
|
|||||||
|
|
||||||
```graphql
|
```graphql
|
||||||
{
|
{
|
||||||
animes(sort: [YEAR_DESC, SEASON]) {
|
animePaginator(sort: [YEAR_DESC, SEASON]) {
|
||||||
data {
|
data {
|
||||||
year
|
year
|
||||||
season
|
season
|
||||||
|
|||||||
Reference in New Issue
Block a user