also removed any references to Anify
This commit is contained in:
45
src/resolvers/queries/home.ts
Normal file
45
src/resolvers/queries/home.ts
Normal file
@@ -0,0 +1,45 @@
|
||||
import { env } from "cloudflare:workers";
|
||||
import { graphql } from "gql.tada";
|
||||
import { GraphQLError } from "graphql";
|
||||
|
||||
import type { GraphQLContext } from "~/graph~/context";
|
||||
import { MediaFragment } from "~/types/title/mediaFragment";
|
||||
|
||||
enum HomeCategory {
|
||||
WATCHING,
|
||||
PLANNING,
|
||||
}
|
||||
|
||||
export async function home(
|
||||
_parent: any,
|
||||
args: { category: HomeCategory; page?: number },
|
||||
context: GraphQLContext,
|
||||
) {
|
||||
const { category, page = 1 } = args;
|
||||
const { user, aniListToken } = context;
|
||||
let statusFilters: string[] = [];
|
||||
switch (category) {
|
||||
case HomeCategory.WATCHING:
|
||||
statusFilters = ["CURRENT"];
|
||||
break;
|
||||
case HomeCategory.PLANNING:
|
||||
statusFilters = ["PLANNING", "PAUSED", "REPEATING"];
|
||||
break;
|
||||
}
|
||||
|
||||
const stub = await env.ANILIST_DO.getByName("GLOBAL");
|
||||
const response = await stub.getTitles(
|
||||
user?.name,
|
||||
page,
|
||||
statusFilters,
|
||||
aniListToken,
|
||||
);
|
||||
|
||||
if (!response) {
|
||||
throw new GraphQLError(`Failed to fetch ${category} titles`, {
|
||||
extensions: { code: "INTERNAL_SERVER_ERROR" },
|
||||
});
|
||||
}
|
||||
|
||||
return response;
|
||||
}
|
||||
Reference in New Issue
Block a user