storybook/scripts/utils/githubClient.ts
2024-07-02 23:41:38 +09:00

24 lines
563 B
TypeScript

const GITHUB_API = 'https://api.github.com/graphql';
export const githubClient = (apiKey: string) => {
return async (query: string, variables?: { [key: string]: any }) => {
const res = await fetch(GITHUB_API, {
method: 'POST',
headers: {
authorization: `token ${apiKey}`,
},
body: JSON.stringify({
query,
variables,
}),
});
const result = await res.json();
const { data, errors } = result;
if (errors) {
throw new Error(JSON.stringify(errors[0]));
}
return data;
};
};