We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent a0168b4 commit bd8c4d8Copy full SHA for bd8c4d8
1 file changed
src/api/api.ts
@@ -0,0 +1,30 @@
1
+const GITHUB_GRAPHQL_URL = "https://api.github.com/graphql";
2
+
3
+export async function githubGraphQL<T>(
4
+ query: string,
5
+ variables: Record<string, any> = {},
6
+ token?: string
7
+): Promise<T> {
8
+ const headers = token
9
+ ? {
10
+ "Content-Type": "application/json",
11
+ Authorization: `bearer ${token}`
12
+ }
13
+ : {
14
+ "Content-Type": "application/json"
15
+ };
16
17
+ const res = await fetch(GITHUB_GRAPHQL_URL, {
18
+ method: "POST",
19
+ headers: headers as HeadersInit,
20
+ body: JSON.stringify({ query, variables })
21
+ });
22
23
+ const json = await res.json();
24
+ console.log(json)
25
+ if (json.errors){
26
+ const error = JSON.stringify(json.errors, null, 2);
27
+ console.log(json.errors)
28
29
+ return json.data;
30
+}
0 commit comments