feat: Implement and register user profile GraphQL resolver
This commit is contained in:
@@ -7,21 +7,23 @@ import { popularBrowse } from "./queries/popularBrowse";
|
|||||||
import { popularByCategory } from "./queries/popularByCategory";
|
import { popularByCategory } from "./queries/popularByCategory";
|
||||||
import { search } from "./queries/search";
|
import { search } from "./queries/search";
|
||||||
import { title } from "./queries/title";
|
import { title } from "./queries/title";
|
||||||
|
import { user } from "./queries/user";
|
||||||
import { Title } from "./title";
|
import { Title } from "./title";
|
||||||
|
|
||||||
export const resolvers = {
|
export const resolvers = {
|
||||||
Query: {
|
Query: {
|
||||||
healthCheck,
|
healthCheck,
|
||||||
title,
|
title,
|
||||||
search,
|
search,
|
||||||
popularBrowse,
|
popularBrowse,
|
||||||
popularByCategory,
|
popularByCategory,
|
||||||
episodeStream,
|
episodeStream,
|
||||||
},
|
user,
|
||||||
Mutation: {
|
},
|
||||||
updateWatchStatus: updateWatchStatusMutation,
|
Mutation: {
|
||||||
markEpisodeAsWatched: markEpisodeAsWatchedMutation,
|
updateWatchStatus: updateWatchStatusMutation,
|
||||||
updateToken: updateTokenMutation,
|
markEpisodeAsWatched: markEpisodeAsWatchedMutation,
|
||||||
},
|
updateToken: updateTokenMutation,
|
||||||
Title,
|
},
|
||||||
|
Title,
|
||||||
};
|
};
|
||||||
|
|||||||
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