feat: Implement and register user profile GraphQL resolver
This commit is contained in:
@@ -7,6 +7,7 @@ import { popularBrowse } from "./queries/popularBrowse";
|
||||
import { popularByCategory } from "./queries/popularByCategory";
|
||||
import { search } from "./queries/search";
|
||||
import { title } from "./queries/title";
|
||||
import { user } from "./queries/user";
|
||||
import { Title } from "./title";
|
||||
|
||||
export const resolvers = {
|
||||
@@ -17,6 +18,7 @@ export const resolvers = {
|
||||
popularBrowse,
|
||||
popularByCategory,
|
||||
episodeStream,
|
||||
user,
|
||||
},
|
||||
Mutation: {
|
||||
updateWatchStatus: updateWatchStatusMutation,
|
||||
|
||||
21
src/graphql/resolvers/queries/user.ts
Normal file
21
src/graphql/resolvers/queries/user.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
import { getUser } from "~/controllers/auth/anilist/getUser";
|
||||
import type { GraphQLContext } from "~/graphql/context";
|
||||
import { GraphQLError } from "graphql";
|
||||
|
||||
export async function user(_parent: any, _args: {}, context: GraphQLContext) {
|
||||
const { aniListToken } = context;
|
||||
if (!aniListToken) {
|
||||
throw new GraphQLError("Unauthorized", {
|
||||
extensions: { code: "UNAUTHORIZED" },
|
||||
});
|
||||
}
|
||||
|
||||
const response = await getUser(aniListToken);
|
||||
if (!response) {
|
||||
throw new GraphQLError(`Failed to fetch user`, {
|
||||
extensions: { code: "INTERNAL_SERVER_ERROR" },
|
||||
});
|
||||
}
|
||||
|
||||
return response;
|
||||
}
|
||||
Reference in New Issue
Block a user