feat: Implement home feed GraphQL resolver
This commit is contained in:
36
src/graphql/resolvers/queries/home.ts
Normal file
36
src/graphql/resolvers/queries/home.ts
Normal 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;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user