import { GraphQLError } from "graphql"; import type { GraphQLContext } from "~/context"; import { fetchPopularTitlesFromAnilist } from "~/services/popular/category/anilist"; import type { PopularCategory } from "~/services/popular/category/enum"; interface PopularByCategoryArgs { category: PopularCategory; page?: number; limit?: number; } export async function popularByCategory( _parent: unknown, args: PopularByCategoryArgs, _context: GraphQLContext, ) { const { category, page = 1, limit = 10 } = args; const response = await fetchPopularTitlesFromAnilist(category, page, limit); if (!response) { throw new GraphQLError(`Failed to fetch ${category} titles`, { extensions: { code: "INTERNAL_SERVER_ERROR" }, }); } return { results: response.results || [], hasNextPage: response.hasNextPage ?? false, }; }