Skip to content

Commit

Permalink
feat: getTwitchUser
Browse files Browse the repository at this point in the history
  • Loading branch information
veryCrunchy committed May 9, 2024
1 parent af03df3 commit 501c687
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 0 deletions.
32 changes: 32 additions & 0 deletions src/gql/resolvers/getTwitchUser.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import axios from "axios";
import { type Resolvers } from ".";
import { getClientToken } from "~/auth";

const watchtimeResolver: Resolvers["Query"] = {
getTwitchUser: async (_, query) => {
const queryString = `${isNaN(Number(query.user)) ? "login" : "id"}=${query.user}`;

const res = await axios.get(
"https://api.twitch.tv/helix/users?" + queryString,
{
headers: {
Authorization: `Bearer ${await getClientToken()}`,
"Client-Id": process.env.TWITCH_CLIENT_ID,
},
}
),
userData = res.data.data as {
id: string;
login: string;
display_name: string;
type: string;
broadcaster_type: string;
description: string;
profile_image_url: string;
view_count: number;
created_at: string;
}[];
return userData;
},
};
export default watchtimeResolver;
2 changes: 2 additions & 0 deletions src/gql/resolvers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { mutationType, queryType } from "../schema";
import { contentQuery, contentMutation } from "./content";
import { whitelistQuery, whitelistMutation } from "./whitelist";
import watchtime from "./watchtime";
import getTwitchUser from "./getTwitchUser";

import me from "./me";
import { InferResolvers } from "garph";
Expand All @@ -16,6 +17,7 @@ export const resolvers = {
...contentQuery,
...me,
...watchtime,
...getTwitchUser,
...whitelistQuery,
},

Expand Down
14 changes: 14 additions & 0 deletions src/gql/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,17 @@ const UserType = g.type("User", {
createdAt: dateType,
updatedAt: dateType,
});
const TwitchUserType = g.type("TwitchUser", {
id: g.id(),
login: g.string(),
display_name: g.string(),
type: g.string(),
broadcaster_type: g.string(),
description: g.string(),
profile_image_url: g.string(),
view_count: g.int(),
created_at: g.string(),
});

const WatchtimeType = g.type("Watchtime", {
time: g.int(),
Expand All @@ -40,6 +51,9 @@ export const queryType = g.type("Query", {
.args({
limit: g.int().default(10),
}),
getTwitchUser: g.ref(TwitchUserType).list().args({
user: g.id(),
}),

checkWhitelist: g.boolean(),
checkWhitelistByUUID: g.boolean().args({
Expand Down

0 comments on commit 501c687

Please sign in to comment.