Some checks failed
Deploy / Deploy (push) Has been cancelled
also removed any references to Anify
33 lines
861 B
TypeScript
33 lines
861 B
TypeScript
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,
|
|
};
|
|
}
|