add toggle/update favourite mutations
This commit is contained in:
parent
a7a9860c0c
commit
5d0d3c33fd
|
@ -13,9 +13,11 @@ import {
|
|||
MutationSaveReviewArgs,
|
||||
MutationSaveThreadArgs,
|
||||
MutationSaveThreadCommentArgs,
|
||||
MutationToggleFavouriteArgs,
|
||||
MutationToggleFollowArgs,
|
||||
MutationToggleLikeArgs,
|
||||
MutationToggleThreadSubscriptionArgs,
|
||||
MutationUpdateFavouriteOrderArgs,
|
||||
MutationUpdateMediaListEntriesArgs,
|
||||
MutationUpdateUserArgs,
|
||||
QueryActivityReplyArgs,
|
||||
|
@ -62,6 +64,7 @@ import { SiteStatistics } from "./queries/SiteStatistics.ts"
|
|||
import { ExternalLinkSourceCollection } from "./queries/ExternalLinkSourceCollection.ts"
|
||||
import { AuthorizationError } from "./utils/AuthorizationError.ts"
|
||||
import { ResponseError } from "./utils/ResponseError.ts"
|
||||
import { Favourites } from "./queries/Favourites.ts"
|
||||
|
||||
const rewriteVarValues = (
|
||||
variable: PropertyKey | unknown | (PropertyKey | unknown)[],
|
||||
|
@ -839,12 +842,31 @@ export const Client = function (auth?: { token: string }) {
|
|||
return this
|
||||
},
|
||||
/** Favourite or unfavourite an anime, manga, character, staff member, or studio */
|
||||
ToggleFavourite() {
|
||||
throw "To be Implemented"
|
||||
ToggleFavourite(args: MutationToggleFavouriteArgs, fn: Fn<typeof Favourites>) {
|
||||
operation = operation.set({
|
||||
level: 1,
|
||||
subField: "ToggleFavourite",
|
||||
hasSubField: true,
|
||||
variables: args,
|
||||
})
|
||||
let tmpQuery
|
||||
fn(Favourites({ query: tmpQuery = [operation], level: 2 }))
|
||||
operation = tmpQuery[0]
|
||||
return this
|
||||
},
|
||||
/** Update the order favourites are displayed in */
|
||||
UpdateFavouriteOrder() {
|
||||
throw "To be Implemented"
|
||||
UpdateFavouriteOrder(args: MutationUpdateFavouriteOrderArgs, fn: Fn<typeof Favourites>) {
|
||||
operation = operation.set({
|
||||
level: 1,
|
||||
subField: "UpdateFavouriteOrder",
|
||||
hasSubField: true,
|
||||
variables: args,
|
||||
})
|
||||
let tmpQuery
|
||||
fn(Favourites({ query: tmpQuery = [operation], level: 2 }))
|
||||
operation = tmpQuery[0]
|
||||
|
||||
return this
|
||||
},
|
||||
/** Create or update a review */
|
||||
SaveReview(
|
||||
|
|
|
@ -0,0 +1,55 @@
|
|||
import { Fields, Fn, UpdateOperation } from "../types/Anilist.ts"
|
||||
import {
|
||||
FavouritesAnimeArgs,
|
||||
FavouritesCharactersArgs,
|
||||
FavouritesMangaArgs,
|
||||
FavouritesStaffArgs,
|
||||
FavouritesStudiosArgs,
|
||||
} from "../types/generated/graphql.ts"
|
||||
import { CharacterConnection } from "./Character.ts"
|
||||
import { MediaConnection } from "./Media.ts"
|
||||
import { StaffConnection } from "./Staff.ts"
|
||||
import { StudioConnection } from "./Studio.ts"
|
||||
|
||||
export const Favourites = ({ query, level }: Fields<UpdateOperation>) => ({
|
||||
/** Favourite anime */
|
||||
withAnime(args: FavouritesAnimeArgs | undefined, fn: Fn<typeof MediaConnection>) {
|
||||
query[0] = query[0].set({ subField: "anime", level, variables: args })
|
||||
let tmpQuery
|
||||
fn(MediaConnection({ query: tmpQuery = [query[0]], level: level + 1 }))
|
||||
query[0] = tmpQuery[0]
|
||||
return this
|
||||
},
|
||||
/** Favourite manga */
|
||||
withManga(args: FavouritesMangaArgs | undefined, fn: Fn<typeof MediaConnection>) {
|
||||
query[0] = query[0].set({ subField: "manga", level, variables: args })
|
||||
let tmpQuery
|
||||
fn(MediaConnection({ query: tmpQuery = [query[0]], level: level + 1 }))
|
||||
query[0] = tmpQuery[0]
|
||||
return this
|
||||
},
|
||||
/** Favourite characters */
|
||||
withCharacters(args: FavouritesCharactersArgs | undefined, fn: Fn<typeof CharacterConnection>) {
|
||||
query[0] = query[0].set({ subField: "characters", level, variables: args })
|
||||
let tmpQuery
|
||||
fn(CharacterConnection({ query: tmpQuery = [query[0]], level: level + 1 }))
|
||||
query[0] = tmpQuery[0]
|
||||
return this
|
||||
},
|
||||
/** Favourite staff */
|
||||
withStaff(args: FavouritesStaffArgs | undefined, fn: Fn<typeof StaffConnection>) {
|
||||
query[0] = query[0].set({ subField: "staff", level, variables: args })
|
||||
let tmpQuery
|
||||
fn(StaffConnection({ query: tmpQuery = [query[0]], level: level + 1 }))
|
||||
query[0] = tmpQuery[0]
|
||||
return this
|
||||
},
|
||||
/** Favourite studios */
|
||||
withStudios(args: FavouritesStudiosArgs | undefined, fn: Fn<typeof StudioConnection>) {
|
||||
query[0] = query[0].set({ subField: "studios", level, variables: args })
|
||||
let tmpQuery
|
||||
fn(StudioConnection({ query: tmpQuery = [query[0]], level: level + 1 }))
|
||||
query[0] = tmpQuery[0]
|
||||
return this
|
||||
},
|
||||
})
|
Loading…
Reference in New Issue