docs: new pagination strategy (#120)

This commit is contained in:
Kyrch
2025-09-01 11:40:41 -03:00
committed by GitHub
parent 2fb4723fe4
commit f862b53a00
5 changed files with 154 additions and 85 deletions
+5 -7
View File
@@ -23,7 +23,7 @@ Most queries provide filtering arguments using the AND operator. Filtering argum
Query example:
```graphql
query {
animePaginator(name_like: "%monogatari%") {
animePagination(name_like: "%monogatari%") {
data {
name
}
@@ -47,7 +47,7 @@ The argument is `trashed: Trashed`, which allows filtering to determine if trash
```graphql
query {
animePaginator(trashed: ONLY) {
animePagination(trashed: ONLY) {
data {
name
}
@@ -55,7 +55,7 @@ query {
}
```
## Nested Filtering
## Relationship Filtering
Filtering in relationships is applied **ONLY** to the relationship and does not affect the previous root.
@@ -64,10 +64,8 @@ query {
anime(slug: "hibike_euphonium") {
name
animethemes(type: OP) {
data {
type
sequence
}
type
sequence
}
}
}
+3 -3
View File
@@ -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\": \"{ animePaginator { data { name } } }\"}"
-d "{\"query\": \"{ animePagination { data { name } } }\"}"
https://graphql.animethemes.moe/
```
@@ -33,7 +33,7 @@ The AnimeThemes API specifies a custom `data` wrap for top-level members that us
The following query
```graphql
query {
animePaginator {
animePagination {
data {
name
}
@@ -44,7 +44,7 @@ will return the JSON:
```json
{
"data": {
"animePaginator": {
"animePagination": {
"data": [
{
"name": ".hack//Liminality"
+6 -6
View File
@@ -6,9 +6,9 @@ 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 `paginationInfo` 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.
The top-level fields that use pagination are singular and have the `Pagination` suffix.
## Arguments
@@ -25,8 +25,8 @@ There are two arguments available for every query that uses pagination.
The following query
```graphql
query {
animePaginator(first: 2, page: 1) {
paginatorInfo {
animePagination(first: 2, page: 1) {
paginationInfo {
count
currentPage
firstItem
@@ -46,8 +46,8 @@ will return the JSON:
```json
{
"data": {
"animePaginator": {
"paginatorInfo": {
"animePagination": {
"paginationInfo": {
"count": 2,
"currentPage": 1,
"firstItem": 1,
+120 -66
View File
@@ -8,24 +8,7 @@ title: Relationships
The AnimeThemes API implements relationships for most types, previously known as "allowed includes" in the REST API.
The many-to-many, one-to-many, and polymorphic one-to-many relationships apply pagination.
## Many-to-One (BelongsTo)
A many-to-one relationship has an object that references the foreign type.
```graphql
query {
animethemePaginator {
data {
sequence
anime {
name
}
}
}
}
```
The many-to-many relationships apply connections. The one-to-many relationships apply simple pagination.
## One-to-Many (HasMany)
@@ -35,9 +18,24 @@ A one-to-many relationship has a list of objects that reference the related type
query {
anime(slug: "hibike_euphonium") {
name
animethemes(first: 2) {
data {
sequence
animethemes(first: 2, type: OP) {
sequence
}
}
}
```
## Inverse One-to-Many (BelongsTo)
An inverse one-to-many relationship has an object that references the foreign type.
```graphql
query {
animethemePagination {
data {
sequence
anime {
name
}
}
}
@@ -61,6 +59,107 @@ and the pivot fields of the relationship.
Both fields `createdAt` and `updatedAt` are available for every many-to-many relationship.
The following query
```graphql
query {
anime(slug: "hibike_euphonium") {
name
series {
pageInfo { # Pagination
total
}
nodes { # Without pivot fields
name
}
edges { # With pivot fields
node {
name
}
createdAt
updatedAt
}
}
}
}
```
will return the JSON:
```json
{
"data": {
"anime": {
"name": "Hibike! Euphonium",
"series": {
"pageInfo": {
"total": 1
},
"nodes": [
{
"name": "Hibike! Euphonium"
}
],
"edges": [
{
"node": {
"name": "Hibike! Euphonium"
},
"createdAt": "2021-03-27 01:58:45",
"updatedAt": "2021-03-27 01:58:45"
}
]
}
}
}
}
```
## Polymorphic One-to-Many (MorphMany)
The relationship of polymorphic one-to-many. Applies simple pagination.
```graphql
query {
membershipPagination {
data {
performances {
alias
as
}
}
}
}
```
## Polymorphic inverse One-to-Many (MorphTo)
The inverse type of polymorphic one-to-many.
A union type indicates that a field might have multiple object types.
```graphql
query {
performancePagination {
data {
artist {
... on Artist {
name
}
... on Membership {
group {
name
}
member {
name
}
}
}
}
}
}
```
## Polymorphic Many-to-Many (MorphToMany)
The polymorphic many-to-many relationship uses the same strategy as the usual [many-to-many](#many-to-many-belongstomany).
The following query
```graphql
query {
@@ -116,49 +215,4 @@ will return the JSON:
}
}
}
```
## Polymorphic Many-to-One (MorphTo)
A union type indicates that a field might have multiple object types.
```graphql
query {
performancePaginator {
data {
artist {
... on Artist {
name
}
... on Membership {
group {
name
}
member {
name
}
}
}
}
}
}
```
## Polymorphic One-to-Many (MorphMany)
The inverse relationship of polymorphic many-to-one. Applies pagination.
```graphql
query {
membershipPaginator {
data {
performances {
data {
alias
as
}
}
}
}
}
```
+20 -3
View File
@@ -17,13 +17,13 @@ To sort in descending order, append `_DESC` to the field name.
```graphql
query {
animePaginator(sort: NAME) { # Sorting in ascending direction.
animePagination(sort: NAME) { # Sorting in ascending direction.
data {
name
}
}
animePaginator(sort: NAME_DESC) { # Sorting in descending direction.
animePagination(sort: NAME_DESC) { # Sorting in descending direction.
data {
name
}
@@ -33,6 +33,23 @@ query {
## Nested Sorting
In one-to-many relationships, it is possible to sort the through a relation.
For example, sort animethemes by their song title.
```graphql
query {
anime(slug: "hibike_euphonium") {
animethemes(sort: SONG_TITLE) {
song {
title
}
}
}
}
```
## Relationship Sorting
It is possible to sort the relationships of the parent type.
```graphql
@@ -53,7 +70,7 @@ By providing a list of enum cases, the sort will be applied in the order of the
```graphql
{
animePaginator(sort: [YEAR_DESC, SEASON]) {
animePagination(sort: [YEAR_DESC, SEASON]) {
data {
year
season