also removed any references to Anify
This commit is contained in:
32
src/resolvers/queries/popularByCategory.ts
Normal file
32
src/resolvers/queries/popularByCategory.ts
Normal file
@@ -0,0 +1,32 @@
|
||||
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,
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user