feat: create route to return title information

Summary:

Test Plan:
This commit is contained in:
2024-05-15 23:03:08 -04:00
parent 695a1bb4cd
commit 68c082493e
18 changed files with 1367 additions and 4 deletions

View File

@@ -0,0 +1,32 @@
import { graphql } from "gql.tada";
import { GraphQLClient } from "graphql-request";
import type { Title } from "~/types/title";
import { MediaFragment } from "./mediaFragment";
const GetTitleQuery = graphql(
`
query GetTitle($id: Int!) {
Media(id: $id) {
...Media
}
}
`,
[MediaFragment],
);
export async function fetchTitleFromAnilist(
id: number,
token: string | undefined,
): Promise<Title | undefined> {
const client = new GraphQLClient("https://graphql.anilist.co/");
const headers = new Headers();
if (token) {
headers.append("Authorization", `Bearer ${token}`);
}
return client
.request(GetTitleQuery, { id }, headers)
.then((data) => data?.Media ?? undefined);
}