feat: Implement home feed GraphQL resolver

This commit is contained in:
2025-12-06 08:26:16 -05:00
parent 4b4eac20a7
commit 5f0302d25a

View File

@@ -0,0 +1,36 @@
import type { GraphQLContext } from "~/graphql/context";
import { GraphQLError } from "graphql";
import { graphql } from "gql.tada";
import { MediaFragment } from "~/types/title/mediaFragment";
import { env } from "cloudflare:workers";
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;
}