feat: Centralize Anilist GraphQL queries, generalize Durable Object for multiple operations with caching, and add new controllers for search, popular titles, user data, and episode tracking.
This commit is contained in:
259
src/libs/anilist/queries.ts
Normal file
259
src/libs/anilist/queries.ts
Normal file
@@ -0,0 +1,259 @@
|
||||
import { graphql } from "gql.tada";
|
||||
|
||||
import { HomeTitleFragment } from "~/types/title/homeTitle";
|
||||
import { MediaFragment } from "~/types/title/mediaFragment";
|
||||
|
||||
export const GetTitleQuery = graphql(
|
||||
`
|
||||
query GetTitle($id: Int!) {
|
||||
Media(id: $id) {
|
||||
...Media
|
||||
}
|
||||
}
|
||||
`,
|
||||
[MediaFragment],
|
||||
);
|
||||
|
||||
export const SearchQuery = graphql(
|
||||
`
|
||||
query Search($query: String!, $page: Int!, $limit: Int!) {
|
||||
Page(page: $page, perPage: $limit) {
|
||||
media(
|
||||
search: $query
|
||||
type: ANIME
|
||||
sort: [POPULARITY_DESC, SCORE_DESC]
|
||||
) {
|
||||
...HomeTitle
|
||||
}
|
||||
pageInfo {
|
||||
hasNextPage
|
||||
}
|
||||
}
|
||||
}
|
||||
`,
|
||||
[HomeTitleFragment],
|
||||
);
|
||||
|
||||
export const GetNextEpisodeAiringAtQuery = graphql(`
|
||||
query GetNextEpisodeAiringAt($id: Int!) {
|
||||
Media(id: $id) {
|
||||
status
|
||||
nextAiringEpisode {
|
||||
episode
|
||||
airingAt
|
||||
}
|
||||
}
|
||||
}
|
||||
`);
|
||||
|
||||
export const MarkEpisodeAsWatchedMutation = graphql(`
|
||||
mutation MarkEpisodeAsWatched($titleId: Int!, $episodeNumber: Int!) {
|
||||
SaveMediaListEntry(
|
||||
mediaId: $titleId
|
||||
status: CURRENT
|
||||
progress: $episodeNumber
|
||||
) {
|
||||
user {
|
||||
id
|
||||
name
|
||||
avatar {
|
||||
medium
|
||||
large
|
||||
}
|
||||
statistics {
|
||||
anime {
|
||||
minutesWatched
|
||||
episodesWatched
|
||||
count
|
||||
meanScore
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
`);
|
||||
|
||||
export const MarkTitleAsWatchedMutation = graphql(`
|
||||
mutation MarkTitleAsWatched($titleId: Int!) {
|
||||
SaveMediaListEntry(mediaId: $titleId, status: COMPLETED) {
|
||||
user {
|
||||
id
|
||||
name
|
||||
avatar {
|
||||
medium
|
||||
large
|
||||
}
|
||||
statistics {
|
||||
anime {
|
||||
minutesWatched
|
||||
episodesWatched
|
||||
count
|
||||
meanScore
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
`);
|
||||
|
||||
export const GetUserQuery = graphql(`
|
||||
query GetUser {
|
||||
Viewer {
|
||||
id
|
||||
name
|
||||
avatar {
|
||||
medium
|
||||
large
|
||||
}
|
||||
statistics {
|
||||
anime {
|
||||
minutesWatched
|
||||
episodesWatched
|
||||
count
|
||||
meanScore
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
`);
|
||||
|
||||
export const GetPopularTitlesQuery = graphql(
|
||||
`
|
||||
query GetPopularTitles(
|
||||
$page: Int
|
||||
$limit: Int
|
||||
$season: MediaSeason
|
||||
$seasonYear: Int
|
||||
) {
|
||||
Page(page: $page, perPage: $limit) {
|
||||
media(
|
||||
type: ANIME
|
||||
sort: POPULARITY_DESC
|
||||
season: $season
|
||||
seasonYear: $seasonYear
|
||||
isAdult: false
|
||||
) {
|
||||
...HomeTitle
|
||||
}
|
||||
pageInfo {
|
||||
hasNextPage
|
||||
}
|
||||
}
|
||||
}
|
||||
`,
|
||||
[HomeTitleFragment],
|
||||
);
|
||||
|
||||
export const GetTrendingTitlesQuery = graphql(
|
||||
`
|
||||
query GetTrendingTitles($page: Int, $limit: Int) {
|
||||
Page(page: $page, perPage: $limit) {
|
||||
media(type: ANIME, sort: TRENDING_DESC, isAdult: false) {
|
||||
...HomeTitle
|
||||
}
|
||||
pageInfo {
|
||||
hasNextPage
|
||||
}
|
||||
}
|
||||
}
|
||||
`,
|
||||
[HomeTitleFragment],
|
||||
);
|
||||
|
||||
export const GetUpcomingTitlesQuery = graphql(
|
||||
`
|
||||
query GetUpcomingTitles(
|
||||
$page: Int!
|
||||
$airingAtLowerBound: Int!
|
||||
$airingAtUpperBound: Int!
|
||||
) {
|
||||
Page(page: $page) {
|
||||
airingSchedules(
|
||||
notYetAired: true
|
||||
sort: TIME
|
||||
airingAt_lesser: $airingAtUpperBound
|
||||
airingAt_greater: $airingAtLowerBound
|
||||
) {
|
||||
id
|
||||
airingAt
|
||||
timeUntilAiring
|
||||
episode
|
||||
media {
|
||||
...Media
|
||||
}
|
||||
}
|
||||
pageInfo {
|
||||
hasNextPage
|
||||
}
|
||||
}
|
||||
}
|
||||
`,
|
||||
[MediaFragment],
|
||||
);
|
||||
|
||||
export const BrowsePopularQuery = graphql(
|
||||
`
|
||||
query BrowsePopular(
|
||||
$season: MediaSeason!
|
||||
$seasonYear: Int!
|
||||
$nextSeason: MediaSeason!
|
||||
$nextYear: Int!
|
||||
$limit: Int!
|
||||
) {
|
||||
trending: Page(page: 1, perPage: $limit) {
|
||||
media(sort: TRENDING_DESC, type: ANIME, isAdult: false) {
|
||||
...HomeTitle
|
||||
}
|
||||
}
|
||||
season: Page(page: 1, perPage: $limit) {
|
||||
media(
|
||||
season: $season
|
||||
seasonYear: $seasonYear
|
||||
sort: POPULARITY_DESC
|
||||
type: ANIME
|
||||
isAdult: false
|
||||
) {
|
||||
...HomeTitle
|
||||
}
|
||||
}
|
||||
nextSeason: Page(page: 1, perPage: 1) {
|
||||
media(
|
||||
season: $nextSeason
|
||||
seasonYear: $nextYear
|
||||
sort: START_DATE_DESC
|
||||
type: ANIME
|
||||
isAdult: false
|
||||
) {
|
||||
nextAiringEpisode {
|
||||
airingAt
|
||||
timeUntilAiring
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
`,
|
||||
[HomeTitleFragment],
|
||||
);
|
||||
|
||||
export const NextSeasonPopularQuery = graphql(
|
||||
`
|
||||
query NextSeasonPopular(
|
||||
$nextSeason: MediaSeason
|
||||
$nextYear: Int
|
||||
$limit: Int!
|
||||
) {
|
||||
Page(page: 1, perPage: $limit) {
|
||||
media(
|
||||
season: $nextSeason
|
||||
seasonYear: $nextYear
|
||||
sort: POPULARITY_DESC
|
||||
type: ANIME
|
||||
isAdult: false
|
||||
) {
|
||||
...HomeTitle
|
||||
}
|
||||
}
|
||||
}
|
||||
`,
|
||||
[HomeTitleFragment],
|
||||
);
|
||||
Reference in New Issue
Block a user